QStateMachine: setup of parallel states and QFinalState
-
I am implementing (Qt5.15.3) a state machine where one of the states (st1 below) is composed of multiple substates (st1X below) that are executed in parallel.
When all substates st1X have finished their work, the state st1 must transition to a new state st2.
According to the documentation, this should be possible with a setup like this:auto st1 = new QState(this); auto st2 = new QState(this); st1->setChildMode(QState::ParallelStates); st1->addTransition(st1, &QState::finished, st2); auto st1F = new QFinalState(st1); for(int i = 0; i < 10; ++i) { auto st1X = new QState(st1); auto w = new Worker(this); st1X->addTransition(w, &Worker::done, st1F); connect(st1X, &QState::entered, w, &Worker::start); }What happens is that the st1 state emits the signal finished() as soon as the first st1X substate has transitioned into st1F, in contradiction to what the documentation states, namely that st1 should emit the signal finished() when all the parallel substates have transitioned into st1F.
The setup is extremely simple, I think I misunderstood something at the documentation level.
-
I got this working, leaving here a comment in case someone else has the same issue.
From Qt docs: "For parallel state groups, the QState::finished() signal is emitted when all the child states have entered final states.".
The missing info is that each substate must have its own child final state. -
M meslor has marked this topic as solved on