0

嗨,伙计们,我真的需要你的帮助我想做的就是缩放图像并使用 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>          ]
4

2 回答 2

2

改成

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

QtConcurrent::map(images,displayImages);

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

编辑 要成为主窗口的一部分,声明函数静态,并调用:

QtConcurrent::map(images,&QMainWindow::displayImages);
于 2012-02-24T10:00:02.690 回答
1

你不能这样做。注意文档

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);
}
于 2012-02-24T10:13:53.463 回答