QtConcurrent::map Doesn't accept parameters

520 views Asked by At

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?

1

There are 1 answers

3
tinkertime On

From the docs Sequence should be taken by reference, not by pointer

QFuture<void> QtConcurrent::map ( Sequence & sequence, MapFunction function )

Try:

SqlLoadingThread=QtConcurrent::map(list, &MainWindow::_fillTreeWithList);

Also, you'll need to make your MapFunction take the parameter (QStringList) by reference:

void _fillTreeWithList(QStringList&);