Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Issue with parallel states and parent transitions
Qt 6.12 LTS is out! See what's new in the release blog

Issue with parallel states and parent transitions

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 637 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AccWhid
    wrote on last edited by
    #1

    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();
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt
    • Unsolved