0

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<void>` to `QFuture<results>`

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.

agold
  • 6,140
  • 9
  • 38
  • 54

1 Answers1

2

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.

ajshort
  • 3,684
  • 5
  • 29
  • 43
  • 1
    [This Qt 5.4 documentation](http://doc.qt.io/qt-5.4/qtconcurrentmap.html) explains, nicely, the difference between the various `QtConcurrent` mapping functions. – RobbieE Oct 07 '15 at 09:53
  • @ajshort Thanks for a reply. I tried that but it still gives the same error. I even tried with a dummy function that returns an `int` and mapped a `QVector` of `ints` to it and even that doesn't work. It works however in a console application without any problems. I am totally lost with this. – Paweł Kaczmarczyk Oct 07 '15 at 12:20