I made want to run a function with QtConcurrent::map, but I always get errors...
I have two functions in Mainwindow: on_listWidget_itemClicked and _fillTreeWithList(QStringList selectedListWidget)
. Function on_listWidget_itemClicked should use map with _fillTreeWithList.
My Code:
Header:
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);
}
Error:
...mainwindow.cpp:56: Error: no matching function for call to 'map(QList<QStringList>*, void (MainWindow::*)(QStringList))'
SqlLoadingThread=QtConcurrent::map(&list, &MainWindow::_fillTreeWithList);
^
Does anyone have any idea how to solve my problem?
From the docs Sequence should be taken by reference, not by pointer
Try:
Also, you'll need to make your MapFunction take the parameter (QStringList) by reference: