我想用QtConcurrent :: map运行一个函数,但我总是得到错误......
我在Mainwindow中有两个函数:on_listWidget_itemClicked and _fillTreeWithList(QStringList selectedListWidget)
。功能on_listWidget_itemClicked should use map with _fillTreeWithList.
我的代码:
标题
QFuture<void> SqlLoadingThread;
void _fillTreeWithList(QStringList);
void on_listWidget_itemClicked(QListWidgetItem *item);
.cpp的:
void MainWindow::on_listWidget_itemClicked(QListWidgetItem *item)
{
QStringList selectedListWidget;
QList<QListWidgetItem *> selected=ui->listWidget->selectedItems();
foreach (QListWidgetItem * item, selected){
selectedListWidget.append(item->text());
}
if(SqlLoadingThread.isRunning()){
SqlLoadingThread.cancel();
}
QList<QStringList> list;
list.append(selectedListWidget);
SqlLoadingThread=QtConcurrent::map(&list, &MainWindow::_fillTreeWithList);
}
错误:
...mainwindow.cpp:56: Error: no matching function for call to 'map(QList<QStringList>*, void (MainWindow::*)(QStringList))'
SqlLoadingThread=QtConcurrent::map(&list, &MainWindow::_fillTreeWithList);
^
有没有人知道如何解决我的问题?
答案 0 :(得分:0)
来自文档序列应该通过引用而不是通过指针
来获取QFuture<void> QtConcurrent::map ( Sequence & sequence, MapFunction function )
尝试:
SqlLoadingThread=QtConcurrent::map(list, &MainWindow::_fillTreeWithList);
此外,您需要让MapFunction通过引用获取参数(QStringList):
void _fillTreeWithList(QStringList&);