类型为'void(ClassName ::)(QString&)'的参数与'void(ClassName ::*)(QString&)'不匹配

Sha*_*fun 0 c++ qt qt4

我试图使用Qt的qtconcurrentmap来处理一些图像,我收到以下错误

argument of type 'void (ClassName::)(QString&)' does not match 'void (ClassName::*)(QString&)
Run Code Online (Sandbox Code Playgroud)

我也来了

/Library/Frameworks/QtCore.framework/Headers/qtconcurrentmapkernel.h:: 
In member function 'bool QtConcurrent::MapKernel<Iterator, MapFunctor>::runIteration(Iterator, int, void*) 
[with Iterator = QList<QString>::iterator, MapFunctor = void (ClassName::*)(QString&)]':


/Library/Frameworks/QtCore.framework/Headers/qtconcurrentmapkernel.h:73: 
error: must use '.*' or '->*' to call pointer-to-member function in 
'((QtConcurrent::MapKernel<QList<QString>::iterator, void (ClassName::*)(QString&)>*)this)->QtConcurrent::MapKernel<QList<QString>::iterator, void (ClassName::*)(QString&)>::map (...)'
Run Code Online (Sandbox Code Playgroud)

这是我的代码

void ClassName::processImage(QString &f)
{

    Image image;
        image.read(qPrintable(f));
        try {
            //Apply effects on an Image
        } catch ( Magick::Exception & error) {
            // Displaying any possible errors on the text browser
            ui->textBrowser_error->setText(error.what());

        }
}



void ClassName::processAll() {

    foreach (QFileInfo f, list)
     {      QString str(f.absoluteFilePath());
            QList<QString> listof;
            listof.append(str);
     }


    QFuture<void> future = QtConcurrent::map(listof, processImage);
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Die*_*lla 7

这里有两件事.首先,变量listofforeach循环内声明,因此在创建时可能不可见future.其次,你应该使用&ClassName::processImage第二个参数来QtConcurrent::map().

更新:

查看文档,您似乎需要编写调用以这种方式创建映射:

QFuture<void> future = QtConcurrent::map(listof, boost::bind(&ClassName::processImage, this));
Run Code Online (Sandbox Code Playgroud)

(你必须使用boost.bind将成员函数转换为普通函数,这是map第二个参数所期望的).