0

I was trying to add progress bar in qt but got the following error:

error: no matching function for call to 'map(QVector<int>&, <unresolved overloaded function type>)'
      futureWatcher.setFuture(QtConcurrent::map(vector, spin));

The code is as follows:

using namespace QtConcurrent;

const int iterations = 20;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QVector<int> vector;
    for (int i = 0; i < iterations; ++i)
        vector.append(i);
    QProgressDialog dialog;
    dialog.setLabelText(QString("Progressing using %1 thread(s)...").arg(QThread::idealThreadCount()));
    QFutureWatcher<void> futureWatcher;

    QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int)));
     QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int)));

     futureWatcher.setFuture(QtConcurrent::map(vector, spin));

  dialog.exec();
}

void MainWindow::spin(int &iteration)
{
    const int work =1000 * 1000 * 40;
    volatile int v =0;
    for(int j = 0; j< work; j++)
        ++v;
    qDebug()<< "iteration" <<iteration <<"in thread"<<QThread::currentThreadId();
}

I am using Qt5.2.1. Unable to recoganise the error. Please help me to solve the error.

charu
  • 65
  • 1
  • 7
  • possible duplicate of [QtConcurrent::map() with member function = can not compile](http://stackoverflow.com/questions/10361044/qtconcurrentmap-with-member-function-can-not-compile) – cmannett85 Feb 26 '15 at 08:38

1 Answers1

0

In this line

futureWatcher.setFuture(QtConcurrent::map(vector, spin));

you should specify spin function's class name and bind spin with your class object, using as ex. std::bind. Or you can use global function alternatively.

Alexander Stepaniuk
  • 6,217
  • 4
  • 31
  • 48
swin
  • 16
  • 1