Im trying to use Qt’s qtconcurrentmap to process some images and I’m getting the following error
argument of type 'void (ClassName::)(QString&)' does not match 'void (ClassName::*)(QString&)
I’m also getting
/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 (...)'
This is my code
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);
}
Any Ideas?
Two things here. First, the variable
listofis declared inside theforeachloop, so it may not be visible at the point of creatingfuture. Second, you should use&ClassName::processImageas the second parameter toQtConcurrent::map().UPDATE:
Looking at the documentation, it seems you need to write the call to create the map this way:
(you have to use
boost.bindto convert a member function into a normal function, that is whatmapexpect as the second argument).