1

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?

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
Kanashius
  • 111
  • 1
  • 3

1 Answers1

1

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&);
tinkertime
  • 2,972
  • 4
  • 30
  • 45
  • Now i get another error: D:\Programme\Qtneu\5.3\mingw482_32\include\QtConcurrent\qtconcurrentmapkernel.h:71: Fehler: no match for call to '(QtConcurrent::MemberFunctionWrapper1) (QStringList&)' map(*it); ^ I tried out a lot, but nothing want to run :) – Kanashius Nov 21 '14 at 16:27
  • added an addendum above – tinkertime Nov 21 '14 at 16:32
  • Same Error: no match for call to '(QtConcurrent::MemberFunctionWrapper1) (QStringList&)' map(*it); ^ – Kanashius Nov 21 '14 at 22:00