添加进度条时出错
Error while adding progess bar
我试图在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。无法重新组织错误。请帮我解决这个错误。
在行中
futureWatcher.setFuture(QtConcurrent::map(vector, spin));
您应该指定spin
函数的类名,并使用例如std::bind
将spin
与类对象绑定。或者您也可以使用全局函数。
相关文章:
- 尝试将另一个子句添加到代码中时出错
- TraciMobility::getExternalId 将自定义模块添加到示例中时出错Veins_Inet (Omne
- libstdc++.so.6:添加符号时出错:命令行中缺少 DSO
- 为什么在函数参数前面添加 const 会出错?
- MySQL C++连接器:添加符号时出错:文件格式无法识别
- 尝试在虚幻引擎中通过C++添加视口时出错"No instance of overloaded function CreateWidget"
- 尝试将数据添加到结构内部的矢量时出错
- 添加按钮时出错,即使存在这样的插槽,也不存在
- 向模板化静态成员初始化添加和不添加'typename'都会出错
- 擦除矢量中的对象时出错.如何将移动作业运算符添加到我的类中
- CMake 和/或在为项目添加提升时出错
- 将元素添加到矢量时出错
- 在二维三角测量中添加约束时出错
- 将事件处理程序添加到任何控件都会导致 Visual Studio 中出错
- 将代码添加到 c++ winAPI 脚本时出错
- Inventor.h中矢量的添加方法出错
- LNK1104将Boost库添加到Qt项目时出错
- 为什么我在向类[C++]添加私有变量时出错
- 将指针添加到不同命名空间中的类时出错
- 添加两个数字(链表中的数字)时出错