PDA

View Full Version : Doubts about QtConcurrent::run and members functions



vcp
13th January 2010, 19:18
Hi All, Happy new year!

I've tried to use QtConcurrent::run with members functions, but I have not had success.
Then I resolved to quiz this example of documentation:



QString string = "red,blue,green";
QFuture<QStringList> future = QtConcurrent::run(string, &QString::split, QString(", "), QString::KeepEmptyParts, Qt::CaseSensitive);
QStringList result = future.result();


But the following error of compilation occurs

qreport.cpp: In constructor 'qreport::qreport()':
qreport.cpp:57: error: no matching function for call to 'run(QString&, <unresolved overloaded function type>, QString, QString::SplitBehavior, Qt::CaseSenitive);

What is happening? :confused:

Thanks in advance.

wysota
13th January 2010, 20:23
I think is should be "QString::split" and not "&QString:split".

vcp
14th January 2010, 11:26
Hi wysota,

Not, unfortunately it is not this the problem.
By the way this topic is really an a lot confused one.
You've some piece of code that use functions member in threads?
It is very difficult find some explanation about this matter.

Thanks a lot.

Rembobo
14th January 2010, 13:50
QString string = "red,blue,green";
typedef QStringList (QString::*splitFunction)(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const;
splitFunction function = &QString::split;
QFuture<QStringList> future = QtConcurrent::run(string, function, QString(","), QString::KeepEmptyParts, Qt::CaseSensitive);
future.waitForFinished();
QStringList sl = future.result();
qDebug() << sl.join(" -- ");
:)
I think it happens because QString split function is overloaded and compiler cannot determine which function is right to use in template. But I could be wrong.

vcp
14th January 2010, 17:30
Thanks Rembobo,

I think that you are not wrong, but the example of the documentation of the Qt is. Or bad formulated.
His explanation does very sense for me.