Proper use of QtConcurrent::map / mapped
-
Hi,
I would like to make use of QtConcurrent::map to iterate over a QStringList.
However I'm a bit lost.
void ThisClass::startScanning()
{
QStringList stuff;
stuff << "hey";
stuff << "woohah";
QFuture<void> future=QtConcurrent::map(stuff,&ThisClass::doStuff);
}void ThisClass::doStuff(QString file)
{
//do stuff with file
}Compiling this returns the error
error: no match for call to '(QtConcurrent::MemberFunctionWrapper1<void, ThisClass, QString>) (QString&)'
I'm fairly new to C++, can anybody help?
Thanks in advance.
-
Hi,
If you refer to "Using Member Functions" section of the "QtConcurrent documentation":http://qt-project.org/doc/qt-4.8/qtconcurrentmap.html .
It states:
QtConcurrent::map(), QtConcurrent::mapped(), and QtConcurrent::mappedReduced() accept pointers to member functions. The member function class type must match the type stored in the sequenceSo in your case your QList should contain "ThisClass" instances.
You can maybe achieve your goal using function objects to wrap your "This class" instance:
@
struct WrapperObject
{
WrapperObject(ThisClass *instance)
: m_instance(instance) { }typedef void result_type; void operator()(const QString &string) { m_instance->doStuff(string); } ThisClass *m_instance;
};
QStringList stuff; stuff << “hey”; stuff << “woohah”; QFuture<void> future = QtConcurrent::maped(stuff, WrapperObject(pMyInstance));
@