我正在尝试使用 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/