термин не относится к функции, принимающей 1 аргумент QtConcurrent - PullRequest
0 голосов
/ 24 февраля 2012

Привет, ребята, мне действительно нужна ваша помощь. Все, что я хочу сделать, - это масштабировать изображение и запускать его, используя QtConcurrent.

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);
}

этот код не компилируется, он продолжает выдавать ошибку

   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>          ]

Ответы [ 2 ]

2 голосов
/ 24 февраля 2012

Изменить на

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

и

QtConcurrent::map(images,displayImages);

Проблема заключается в том, что вы передаете ссылку на функцию при вызове map, а функция-член нуждается в объекте, на который ссылаются.

Редактировать Чтобы быть частью главного окна, объявите функцию статической и вызовите:

QtConcurrent::map(images,&QMainWindow::displayImages);
1 голос
/ 24 февраля 2012

Вы не можете этого сделать. Обратите внимание на документацию :

QtConcurrent :: map (), QtConcurrent :: mapped () и QtConcurrent :: mappedReduced () принимает указатели на функции-члены. Тип класса функции-члена должен соответствовать типу, сохраненному в последовательности

Перефразируя его, в вашем случае вы можете использовать только функции-члены класса QPixmap.

Однако вы можете достичь желаемого, сделав функцию displayImage внешней:

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);
}
...