0

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>          ]
Poka Yoke
  • 373
  • 3
  • 8
  • 27

2 Answers2

2

Change to

void displayImages( QPixmap &image)
{
  image = image.scaled(100,100,Qt::KeepAspectRatio,Qt::FastTransformation); 
}

and

QtConcurrent::map(images,displayImages);

The issue is that you pass a reference to a function when calling map, and a member function need the referenced object.

Edit To be part of main window declare the function static, and call :

QtConcurrent::map(images,&QMainWindow::displayImages);
UmNyobe
  • 22,539
  • 9
  • 61
  • 90
  • I tried that as well but it gives me a list of errors telling me that 3 arguments are expected and 2 provided. To solve this I tried passing iterators like this QtConcurrent::map(images.begin(),images.end(),isplayImages); but I get and error telling me the opposite 3 provided 2 expected !!! – Poka Yoke Feb 24 '12 at 10:04
  • and the first change you are telling me about is exactly what I'm doing .. or am I missing something? – Poka Yoke Feb 24 '12 at 10:06
  • Ok.. so you meant that it shouldn't be a part of the MainWindow so now it works thanks :) – Poka Yoke Feb 24 '12 at 10:15
  • it can be part of main window but it must be static. see edit. – UmNyobe Feb 24 '12 at 10:19
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);
}
pnezis
  • 12,023
  • 2
  • 38
  • 38