术语不评估为采用1个参数QtConcurrent的函数

时间:2012-02-24 09:46:13

标签: c++ multithreading visual-studio-2010 qt qtconcurrent

大家好我真的需要你的帮助 我想要做的就是缩放图像并使用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 个答案:

答案 0 :(得分:2)

更改为

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

QtConcurrent::map(images,displayImages);

问题是您在调用map时传递对函数的引用,而成员函数需要引用的对象。

修改 要成为主窗口的一部分,请将函数声明为static,并调用:

QtConcurrent::map(images,&QMainWindow::displayImages);

答案 1 :(得分:1)

你做不到。请注意documentation

  

QtConcurrent :: map(),QtConcurrent :: mapped()和   QtConcurrent :: mappedReduced()接受指向成员函数的指针。   成员函数类类型必须与序列中存储的类型匹配

改写它,在你的情况下你只能使用}类的成员函数。

然而,您可以通过将QPixmap函数设置为外部来实现您想要的功能:

displayImage