我试图在qt中添加进度条但出现以下错误:
error: no matching function for call to 'map(QVector<int>&, <unresolved overloaded function type>)'
futureWatcher.setFuture(QtConcurrent::map(vector, spin));
代码如下:
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();
}
我正在使用Qt5.2.1。无法识别错误。请帮我解决错误。
答案 0 :(得分:0)
在这一行
futureWatcher.setFuture(QtConcurrent::map(vector, spin));
你应该指定spin
函数的类名,并使用你的类对象绑定spin
,使用ex。 std::bind
。或者您也可以使用全局功能。