Error with sequence argument when using QtConcurrent map

Go To StackoverFlow.com

0

I'm trying to use QtConcurrent::map to run this function

//This function is used through QtConcurrent::map to create images from a QString path
void MainWindow::createQImage(QString* path) {
    //create an image from the given path
    QImage* t = new QImage(*path);
    imageList->append(t);
}

on this container/sequence (declared in the mainwindow header and initialized in the mainwindow constructor)

QList<QImage *> *imageList = new QList<QImage *>;

Here's the code I'm trying to run

QFutureWatcher<void> futureWatcher;
futureWatcher.setFuture(QtConcurrent::map(imageList, &MainWindow::createQImage));

and here are the errors I'm getting:

request for member 'begin' in 'sequence', which is of non-class type 'QList<QImage*>*'
request for member 'end' in 'sequence', which is of non-class type 'QList<QImage*>*'

I need the "createQImage" function to be run for every element in "imageList," which can reach into the thousands. I believe the problem to be with the first parameter to the map function. And from what I've read, it may have to do with compatibility. There isn't much sample code online that I was able to relate to. I'm new to Qt and not the most experienced of programmers but I'd appreciate some help and feedback.

Alternatively, is there better way to do this using QtConcurrent?

Thanks in advance!

2012-04-05 21:35
by jdjalm
On a side note, if implemented correctly (see other answers), this will do nothing. QtConcurrent::map() iterates over each element in the given list. Since you only create and append the elements in the map-function, your imageList would initially be empty and thus your createQImage() will never be called. Instead, you could use a non-empty, null-filled QVector<QImage*> imageList(numberOfImagesYouNeed, Q_NULLPTR) and pass that to map() - Martin Hennings 2018-09-20 10:39


2

QtConcurrent::map wants a sequence as its first argument. You passed it a pointer to a sequence.

If you do

futureWatcher.setFuture(QtConcurrent::map(*imageList, &MainWindow::createQImage));

it should be happy.

Note that the compiler was reasonably clear about what the problem was. Take the time to read the errors carefully, they're usually not as cryptic as they perhaps at first seem. In this case it was telling you that the argument you passed was not of a class type. A quick look at the argument type at the end of the error reveals that it is a pointer.

2012-04-05 21:45
by Troubadour


1

QList, QImage, QString are Copy-On-Write types (see other Qt implicitly shared types), so you shouldn't use pointers to these types because they are basically already smart pointers.

And if you remove all pointers from your code, it should also fix the main problem.

2012-04-05 22:58
by alexisdm
Ads