c++qtqstatemachine

QStateMachine immediate transition from dummy state


In order to set an object property depending on a transition I need two intermediate states that immediately transition further:

   A       initial state
 Ta Tb     different transitions
 Aa  Ab    (these are only used to set an objects property depending on transition)
 TB TB     both should immediately "transit"
   B       objects property used via entered()/exited() signals

(Alternatively, B probably could be duplicated to set each respective property directly.)

Could a state's entered() signal be used as its own transition source?


Solution

  • Simply add an unconditional transition to the state:

    TB->addTransition(B);
    

    This is idiomatic and also cheaper than using a QSignalTransition coupled to the entered() signal.

    Ref: http://doc.qt.io/qt-5/statemachine-api.html#targetless-transitions