Easy way to "reuse" transitions from State Machine Framework
-
wrote on 16 Jul 2018, 18:33 last edited by
Hello,
I'm designing an application in which I make use of the SMF to help synchronize some of the widgets depending on user interaction.
The problem I have is that there are some situations in which, for a one same action taken by the user (in a particular case, a
KeyPress
event), I must transition to a particular state A if I'm in one of the {B,C,D,F} states (state names for example purpose).So, what I have to do is add, for each of the states in {B,C,D,F}, one
QEventTransition
of typeQEvent::KeyPress
, all of them having the same destination. But as the states claim ownership of transitions, I cannot new up a singleQEventTransition
and pass it to those states, forcing me to replicate the code several times.Is this really the way? Isn't there any way to reuse a transition, or even "clone" one to avoid so much retyping?
QEventTransition *t_maybeNewEntry = Q_NULLPTR; t_maybeNewEntry = new QEventTransition( mainWindow.ui->lineEditOutput, QEvent::KeyPress ); t_maybeNewEntry->setTargetState(s_hasEntry); //... t_maybeNewEntry = new QEventTransition( mainWindow.ui->lineEditOutput, QEvent::KeyPress ); t_maybeNewEntry->setTargetState(s_hasEntry); //... t_maybeNewEntry = new QEventTransition( mainWindow.ui->lineEditOutput, QEvent::KeyPress ); t_maybeNewEntry->setTargetState(s_hasEntry); //... ... ...
Thank you.
-
wrote on 16 Jul 2018, 18:52 last edited by MrShawn
Have a look at the State Machine Framework documentation here.
Basically make one state with your defined transition, and create your other states accordingly with the parent state that has your single transition defined.
Good luck.
1/2