PDA

View Full Version : Problem with QtConcurrent::map arguments



jalm
5th April 2012, 05:43
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 (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(imageLis t, &MainWindow::createQImage));

and here's the error 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 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.

Lykurg
5th April 2012, 07:17
create a function which returns the image, then an additional slot connected to the ready signal of the future watcher. In that add the image to the imageList. Otherwise you have to lock/protect imageList in the createQImage function because of the used thread.