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

标签 c++ qt qt4

我正在尝试使用 Qt 的 qtconcurrentmap处理一些图像时出现以下错误

argument of type 'void (ClassName::)(QString&)' does not match 'void (ClassName::*)(QString&)

我也得到了

/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 (...)'

这是我的代码

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

有什么想法吗?

最佳答案

这里有两件事。首先,变量 listof 是在 foreach 循环内声明的,因此在创建 future 时它可能不可见。其次,您应该使用 &ClassName::processImage 作为 QtConcurrent::map() 的第二个参数。

更新:

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

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

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

关于c++ - 'void (ClassName::)(QString&)' 类型的参数与 'void (ClassName::*)(QString&)' 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4392352/

相关文章:

C++专门化模板类函数而无需重复代码

c++ - 如何使用 qml 组件创建插件的 deb 包(无 C++)

c++ - 你如何序列化一个QMap?

python - 如何在 QT (PyQT) 中实现类似于 Google Image 搜索的布局?

c++ - 全局变量(再次)

c++ - C++中的动态参数化构造函数问题

c++ - 带有刻度文本标签的 Qt slider 小部件

c++ - Qt 4 中有原生窗口动画吗?

c++ - 无法将选项卡中的 Qwidgets 复制到新选项卡

c++ - Intel/AMD C++ 上的 OpenGL 3+ 失败