Issue with parallel states and parent transitions



  • I have run into an issue with parallel states and parent transitions.

    Take the state machine below. It is an extension of the basic string match example where a state will transition if an event with a matching string is posted to the state machine. In the below example, if I post a string of "testSuper" the state machine will transition to "Sub State 3". However, if I remove subState3 and change subStateTransition to not have a target state, then posting a message with string "testSuper" will result in the machine going into the "Fault State". Essentially, I am seeing behavior where both a sub state's transition and a super state's transition onTransition method is being called when a sub state's transition in a parallel state has no target state. However, if there is a target state then only the sub state's transition onTransition is called.

    Is this expected behavior?

    QNamedState* superState = new QNamedState("Super State", nullptr);
    	QState* parallelState = new QState(QStateMachine::ParallelStates, superState);
    	QState* parallel1 = new QState(parallelState);
    	QState* parallel2 = new QState(parallelState);
    	
    	
    	QNamedState* subState1 = new QNamedState("Sub State 1", parallel1);
    	QNamedState* subState2 = new QNamedState("Sub State 2", parallel2);
    	QNamedState* subState3 = new QNamedState("Sub State 3", parallel1);
    	
    	parallel1->setInitialState(subState1);
    	parallel2->setInitialState(subState2);
    
    	QNamedState* faultState = new QNamedState("Fault State", nullptr);
    
    	QNamedStateTransition* faultStateTransition = new QNamedStateTransition("testSuper", "Super transition");
    	faultStateTransition->setTargetState(faultState);
    	superState->addTransition(faultStateTransition);
    
    //Below will transition into "Sub State 3"
    
    	QNamedStateTransition* subStateTransition = new QNamedStateTransition("testSuper", "Base transition");
    	subStateTransition->setTargetState(subState3);
    	subState1->addTransition(subStateTransition);
    
    /*
    This code will transition into "Fault State"
    
            QNamedStateTransition* subStateTransition = new QNamedStateTransition("testSuper", "Base transition");
    	subState1->addTransition(subStateTransition);
    */
    
    	QNamedStateTransition* bogusTransition = new QNamedStateTransition("bogusTest", "Bogus Transition");
    	subState2->addTransition(bogusTransition);
    
    	stateMachine.addState(superState);
    	stateMachine.addState(faultState);
    	stateMachine.setInitialState(superState);
    	superState->setInitialState(parallelState);
    
    	stateMachine.start();
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.