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であり、メンバー関数には参照されるオブジェクトが必要です。

編集 メインウィンドウの一部になるには、関数staticを宣言し、次を呼び出します。

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 に答える