How to use QtConcurrent::functions and what is my error?
Solved
General and Desktop
-
Hello everyone!
I have a list of strings and I want to process them in parallel performing some actions on them. However, when I try to build my code, I have an error stating that the desired function cannot be called. What is my problem?Here's the code I'd like to run:
QStringList filePaths; QString Controller::action(QString& str) { // make some actions on files return str; // I don't really care about the return value. } QtConcurrent::map(filePaths, &Controller::action);
When I try to build my code I get a following error:
C:\Qt\5.15.2\mingw81_64\include\QtConcurrent\qtconcurrentmap.h:49: In file included from C:/Qt/5.15.2/mingw81_64/include/QtConcurrent/qtconcurrentmap.h:49, In file included from C:/Qt/5.15.2/mingw81_64/include/QtConcurrent/qtconcurrentmap.h:49, from C:/Qt/5.15.2/mingw81_64/include/QtConcurrent/QtConcurrentMap:1, from C:/copyrightadder/src/Controllers/Controller.cpp:10: C:/Qt/5.15.2/mingw81_64/include/QtConcurrent/qtconcurrentfunctionwrappers.h:132:14: note: candidate: 'T QtConcurrent::MemberFunctionWrapper1<T, C, U>::operator()(C&, U) [with T = QString; C = Controller; U = QString&]' inline T operator()(C &c, U u) ^~~~~~~~ C:/Qt/5.15.2/mingw81_64/include/QtConcurrent/qtconcurrentfunctionwrappers.h:132:14: note: candidate expects 2 arguments, 1 provided
-
Hi,
If you want to use a member function, the array you pass to the map method must contain items of that class.