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. QtStateMachine does not support blocking transitions?
Qt 6.11 is out! See what's new in the release blog

QtStateMachine does not support blocking transitions?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 650 Views 1 Watching
  • 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.
  • K Offline
    K Offline
    Kursat
    wrote on last edited by
    #1

    I'm trying to implement a custom communication protocol as a state machine on a single thread. I receive messages from wherever and my state machine forwards the messages to the current state via direct function calls and signal / slots. The states are supposed to transition to the appropriate ones depending on the content of the messages.

    The problem is I can't directly trigger transitions synchronously. Say I have state A and B, I receive 2 messages over UDP so I emit two signals. The first message arrives at A and tries to transition to B, but since the transition is done over the event loop; the signal / slot of the second message blocks it. So the second message arrives at A too, when it is supposed to arrive at B.

    I know this is expected behavior since signal / slots translate to direct calls but I need the same behavior from my state transitions and I couldn't find any way to do that using the QStateMachine API. I've thought of a few solutions such as:

    • Separate the message and state machine mechanisms into two threads
    • Somehow notify the machine that a transition event is waiting in the loop so it doesn't direct messages to states but to a buffer until the transition is done

    Am I missing something or is going around the QStateMachine framework the way forward here?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Maybe using an event based transition could be the solution. Please check the corresponding exemple here.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • K Offline
        K Offline
        Kursat
        wrote on last edited by Kursat
        #3

        Thanks, I'll try it but I don't see how that will help. I already have signal transitions and they do the same thing, they post events to the statemachine. I need to bypass the event loop and make the state transition immediate.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          To me it seems that there might be an issue in your state machine design.

          Can you maybe provide a drawing showing it and how it should work ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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