Hi guys I really need your help All I want to do is to scale an image and run it using QtConcurrent .. I followed the documentation exactly but still I can't catch where is my fault here is the code
void MainWindow::displayImages( QPixmap &image)
{
image = image.scaled(100,100,Qt::KeepAspectRatio,Qt::FastTransformation);
}
void MainWindow::showImages()
{
QList <QPixmap> images ;
foreach(imageName,imageList)
{
imageNames.push_back(imageName.toStdString());
image.load(imageName,"4",Qt::AutoColor);
images.push_back(image);
}
QtConcurrent::map(images,&MainWindow::displayImages);
}
this code doesn't compile it keeps giving me the error
1>c:\qt\4.7.1\src\corelib\concurrent\qtconcurrentmapkernel.h(73): error C2064: term does not evaluate to a function taking 1 arguments
1> c:\qt\4.7.1\src\corelib\concurrent\qtconcurrentmapkernel.h(72) : while compiling class template member function 'bool QtConcurrent::MapKernel<Iterator,MapFunctor>::runIteration(Iterator,int,void *)'
1> with
1> [
1> Iterator=QList<QPixmap>::iterator,
1> MapFunctor=void (__thiscall MainWindow::* )(QPixmap &)
1> ]
1> c:\qt\4.7.1\src\corelib\concurrent\qtconcurrentmapkernel.h(201) : see reference to class template instantiation 'QtConcurrent::MapKernel<Iterator,MapFunctor>' being compiled
1> with
1> [
1> Iterator=QList<QPixmap>::iterator,
1> MapFunctor=void (__thiscall MainWindow::* )(QPixmap &)
1> ]
1> c:\qt\4.7.1\src\corelib\concurrent\qtconcurrentmap.h(113) : see reference to function template instantiation 'QtConcurrent::ThreadEngineStarter<void> QtConcurrent::startMap<QList<T>::iterator,MapFunctor>(Iterator,Iterator,Functor)' being compiled
1> with
1> [
1> T=QPixmap,
1> MapFunctor=void (__thiscall MainWindow::* )(QPixmap &),
1> Iterator=QList<QPixmap>::iterator,
1> Functor=void (__thiscall MainWindow::* )(QPixmap &)
1> ]
1> c:\main\work\extend3d\git\square-marker-tools\bundleadjustment\mainwindow.cpp(307) : see reference to function template instantiation 'QFuture<void> QtConcurrent::map<QList<T>,void(__thiscall MainWindow::* )(QPixmap &)>(Sequence &,MapFunctor)' being compiled
1> with
1> [
1> T=QPixmap,
1> Sequence=QList<QPixmap>,
1> MapFunctor=void (__thiscall MainWindow::* )(QPixmap &)
1> ]
You cannot do that. Notice the documentation:
QtConcurrent::map(), QtConcurrent::mapped(), and QtConcurrent::mappedReduced() accept pointers to member functions. The member function class type must match the type stored in the sequence
Rephrasing it, in your case you can only use member functions of the QPixmap
class.
You could however achieve what you want by making the displayImage
function external:
void displayImages( QPixmap &image)
{
image = image.scaled(100,100,Qt::KeepAspectRatio,Qt::FastTransformation);
}
void MainWindow::showImages()
{
QList <QPixmap> images ;
foreach(imageName,imageList)
{
imageNames.push_back(imageName.toStdString());
image.load(imageName,"4",Qt::AutoColor);
images.push_back(image);
}
QtConcurrent::map(images,displayImages);
}