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, move to next state when multiple events of previous state have finished
QtWS25 Last Chance

QStateMachine, move to next state when multiple events of previous state have finished

Scheduled Pinned Locked Moved Unsolved General and Desktop
qstatemachineqstatetransitions
3 Posts 2 Posters 307 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.
  • Pl45m4P Online
    Pl45m4P Online
    Pl45m4
    wrote on last edited by Pl45m4
    #1

    Re: Widget signal chaining

    Hi,

    referring to my topic above.
    I am still working on this project here and there and now decided to have a look at QStateMachine, as mentioned in the Qt Wiki article linked by @Christian-Ehrlicher.

    By design, I'm planning to chain multiple states together, each connected to 1-n "tasks", which are performed when entering a state.

    I'm new to the QStateMachine framework, but already read about transitions, events, bindings and so on.

    Unfortunately I still can't figure out how to change the state, when all actions of the previous state have finished.
    The state "actions" might not be linear every time (see the "graph" in my original topic). In some cases a state is defined by multiple actions... then I want to transition to the next state when the last (the slowest) finished its work.

    Is simply counting them down to 0 and then trigger the transition to the next state a valid solution?

    Or is there a better way using some QState / QStateMachine magic?

    Edit:
    Secondary question:
    As a first test I've added QAbstractState subclasses to my QStateMachine, but I have no clue how to transition between them.
    All I can do is implementing the virtual onExit() and onEntry(), which I did, but functions like

    firstState->addTransition(smm, &StateMachineManager::nextState, secondState);
    

    from QState are not available for QAbstractState subclasses.
    So how do I tell the machine to go from one QAbstractState to another?
    Maybe better use QState subclasses?!

    It also feels like a state machine could be exactly what I need, but QStateMachine has many drawbacks as I've discovered already...
    I need to be able to remove my states. In order to remove states properly, QStateMachine has to be stopped (fine with that).
    A start() will re-start everything. It seems there is no pause() to keep every state as it is and continue from there after one or more state(s) got removed and the gap was "closed" (will be handled by me to connect states before and after the removed one again).
    Any ideas?


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    JonBJ 1 Reply Last reply
    0
    • Pl45m4P Pl45m4

      Re: Widget signal chaining

      Hi,

      referring to my topic above.
      I am still working on this project here and there and now decided to have a look at QStateMachine, as mentioned in the Qt Wiki article linked by @Christian-Ehrlicher.

      By design, I'm planning to chain multiple states together, each connected to 1-n "tasks", which are performed when entering a state.

      I'm new to the QStateMachine framework, but already read about transitions, events, bindings and so on.

      Unfortunately I still can't figure out how to change the state, when all actions of the previous state have finished.
      The state "actions" might not be linear every time (see the "graph" in my original topic). In some cases a state is defined by multiple actions... then I want to transition to the next state when the last (the slowest) finished its work.

      Is simply counting them down to 0 and then trigger the transition to the next state a valid solution?

      Or is there a better way using some QState / QStateMachine magic?

      Edit:
      Secondary question:
      As a first test I've added QAbstractState subclasses to my QStateMachine, but I have no clue how to transition between them.
      All I can do is implementing the virtual onExit() and onEntry(), which I did, but functions like

      firstState->addTransition(smm, &StateMachineManager::nextState, secondState);
      

      from QState are not available for QAbstractState subclasses.
      So how do I tell the machine to go from one QAbstractState to another?
      Maybe better use QState subclasses?!

      It also feels like a state machine could be exactly what I need, but QStateMachine has many drawbacks as I've discovered already...
      I need to be able to remove my states. In order to remove states properly, QStateMachine has to be stopped (fine with that).
      A start() will re-start everything. It seems there is no pause() to keep every state as it is and continue from there after one or more state(s) got removed and the gap was "closed" (will be handled by me to connect states before and after the removed one again).
      Any ideas?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Pl45m4
      I know nothing since I have never used QStateMachine :) But doesn't stop me reading up and poking my nose in.

      The only thing I see for detecting "when all actions of the previous state have finished"/" then I want to transite to the next state when the last (the slowest) finished its work." is if you can take advantage of parallel states:
      Detecting that a Composite State has Finished

      For parallel state groups, the QState::finished() signal is emitted when all the child states have entered final states.

      Otherwise I assume your "Is simply counting them down to 0", or doing some kind of polling for finished, is acceptable.

      Pl45m4P 1 Reply Last reply
      2
      • JonBJ JonB

        @Pl45m4
        I know nothing since I have never used QStateMachine :) But doesn't stop me reading up and poking my nose in.

        The only thing I see for detecting "when all actions of the previous state have finished"/" then I want to transite to the next state when the last (the slowest) finished its work." is if you can take advantage of parallel states:
        Detecting that a Composite State has Finished

        For parallel state groups, the QState::finished() signal is emitted when all the child states have entered final states.

        Otherwise I assume your "Is simply counting them down to 0", or doing some kind of polling for finished, is acceptable.

        Pl45m4P Online
        Pl45m4P Online
        Pl45m4
        wrote on last edited by Pl45m4
        #3

        @JonB

        Thanks for your reply.
        Will see what I can do

        The struggle is actually to figure out what I can use without leading to further issues later.

        Currently I'm fine with a counter and then fire my signal once it reaches 0.


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        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 Extensions
        • Unsolved