Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QStateMachine: setup of parallel states and QFinalState
Forum Updated to NodeBB v4.3 + New Features

QStateMachine: setup of parallel states and QFinalState

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 325 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.
  • M Offline
    M Offline
    meslor
    wrote on last edited by meslor
    #1

    I am implementing (Qt5.15.3) a state machine where one of the states (st1 below) is composed of multiple substates (st1X below) that are executed in parallel.
    When all substates st1X have finished their work, the state st1 must transition to a new state st2.
    According to the documentation, this should be possible with a setup like this:

    auto st1 = new QState(this);
    auto st2 = new QState(this);
    
    st1->setChildMode(QState::ParallelStates);
    st1->addTransition(st1, &QState::finished, st2);
    
    auto st1F = new QFinalState(st1);
    
    for(int i = 0; i < 10; ++i)
    {
      auto st1X = new QState(st1);
      auto w = new Worker(this);
      st1X->addTransition(w, &Worker::done, st1F);
    
      connect(st1X, &QState::entered, w, &Worker::start);
    }
    

    What happens is that the st1 state emits the signal finished() as soon as the first st1X substate has transitioned into st1F, in contradiction to what the documentation states, namely that st1 should emit the signal finished() when all the parallel substates have transitioned into st1F.

    The setup is extremely simple, I think I misunderstood something at the documentation level.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      meslor
      wrote on last edited by
      #2

      I got this working, leaving here a comment in case someone else has the same issue.
      From Qt docs: "For parallel state groups, the QState::finished() signal is emitted when all the child states have entered final states.".
      The missing info is that each substate must have its own child final state.

      1 Reply Last reply
      0
      • M meslor has marked this topic as solved on

      • Login

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