QStateMachine, move to next state when multiple events of previous state have finished
-
Hi,
referring to my topic above.
I am still working on this project here and there and now decided to have a look atQStateMachine
, as mentioned in the Qt Wiki article linked by @Christian-Ehrlicher.By design, I'm planning to chain multiple states together, each connected to 1-n "tasks", which are performed when entering a state.
I'm new to the
QStateMachine
framework, but already read about transitions, events, bindings and so on.Unfortunately I still can't figure out how to change the state, when all actions of the previous state have finished.
The state "actions" might not be linear every time (see the "graph" in my original topic). In some cases a state is defined by multiple actions... then I want to transition to the next state when the last (the slowest) finished its work.Is simply counting them down to 0 and then trigger the transition to the next state a valid solution?
Or is there a better way using some
QState
/QStateMachine
magic?Edit:
Secondary question:
As a first test I've addedQAbstractState
subclasses to myQStateMachine
, but I have no clue how to transition between them.
All I can do is implementing the virtualonExit()
andonEntry()
, which I did, but functions likefirstState->addTransition(smm, &StateMachineManager::nextState, secondState);
from
QState
are not available forQAbstractState
subclasses.
So how do I tell the machine to go from oneQAbstractState
to another?
Maybe better useQState
subclasses?!It also feels like a state machine could be exactly what I need, but
QStateMachine
has many drawbacks as I've discovered already...
I need to be able to remove my states. In order to remove states properly,QStateMachine
has to be stopped (fine with that).
Astart()
will re-start everything. It seems there is nopause()
to keep every state as it is and continue from there after one or more state(s) got removed and the gap was "closed" (will be handled by me to connect states before and after the removed one again).
Any ideas? -
@Pl45m4
I know nothing since I have never usedQStateMachine
:) But doesn't stop me reading up and poking my nose in.The only thing I see for detecting "when all actions of the previous state have finished"/" then I want to transite to the next state when the last (the slowest) finished its work." is if you can take advantage of parallel states:
Detecting that a Composite State has FinishedFor parallel state groups, the
QState::finished()
signal is emitted when all the child states have entered final states.Otherwise I assume your "Is simply counting them down to 0", or doing some kind of polling for finished, is acceptable.