TAGS :Viewed: 11 - Published at: a few seconds ago

[ QtConcurrent map error c2440 ]

I'm making an app for recognizing license plates in images. It works fine, but now I want to move the image analysis part of the code to a separate thread. I'm using Qt 5.4. After reading the documentation I decided that QtConcurrent::map was the right thing to use because before processing the images the user loads files (only their names) which are stored in a list. Here's some code:

Definition of the function that's supposed to be run in a thread:

results detectPlates(const QString &file);

Attempt to use multithreading:

QFuture<results> r = QtConcurrent::map(files, &MainWindow::detectPlates)

files is defined as QList<QString> results is a type defined inside a library that i am using, if that is important.

This doesn't compile with the error :

C2440 'initializing' cannot convert from `QFuture&lt;void&gt;` to `QFuture&lt;results&gt;`

When I modify the function to be <void> then I get:

error c2064: term does not evaluate to a function taking 1 argument.

What is the problem? I would appreciate any help.

Answer 1


QtConcurrent::map modifies the items in place, and returns a void future. If you want to return the result in the form of a QFuture<T>, you will want to use QtConcurrent::mapped.