Solved Error on QtConcurrent::run
-
@peter-70 What is the type of synchronizer? It should be QFutureSynchronizer<void> to match PositionGroupbox::Select() signature.
-
Does
PositionGroupbox
derive fromQWidget
directly or indirectly? -
@KroMignon said in Error on QtConcurrent::run:
QT += concurrent
Good idea, but unfortunately it does not help
-
@peter-70
if you forgotQT += concurrent
inside your *pro file, you have to do a complete rebuild - deleting build folder running qmake - for it to take effect, after adding it!Did you do that?
-
Yes, PositionGroupbox derive from QWidget directly. But What does it matter?
-
@J.Hilk At first, I did not do it. Now I've deleted the output folder and the makefile. Then recreate the makefile and invoke rebuild my project. But that does not help either :-(
-
It should be QFutureSynchronizer<void> to match PositionGroupbox::Select() signature
Yes it is!
Here is the code snippet:
QFutureSynchronizer<void> synchronizer; while ((rc = position.Fetch()) && rowIndex < itemsCount) { auto p = new Position; p->Copy(&position); auto positionWidget = new PositionGroupbox(p, this); p->SetContainer(positionWidget); synchronizer.addFuture(QtConcurrent::run(positionWidget, &PositionGroupbox::Select, false));
-
@peter-70 This sound very strange to me.
I have used QtConcurrent::run() and never run in this error.
I think you have include header:
#include <QtConcurrent/QtConcurrent>
Can you show the declaration of PositionGroupbox::Select?
-
Can you show the declaration of PositionGroupbox::Select?
Yes, the include is as you write it here. But the declaration of PositionGroupbox::Select is the right question and solution!!!
100 points for you! ;-)
The declaration is:
void Select(bool isSelected, bool refreshColors = false);
Now I call
synchronizer.addFuture(QtConcurrent::run(positionWidget, &PositionGroupbox::Select, false, false));
and everything is ok!
@all: Thank you very much! Specially for KroMignon :-)
-
@peter-70 your welcome
-
@peter-70 said in Error on QtConcurrent::run:
Yes, PositionGroupbox derive from QWidget directly. But What does it matter?
It matters quite a lot.
QWidget
is not thread-safe and it's not reentrant. You can't touch anythingQWidget
-y outside the GUI thread, including creating the actual object. Failing to observe this is a race condition and ultimately a bug. That is to say, you have bigger problems than a syntax error.