QStateMachine Order of Event Handling

  • I had a question about the order of event handling in QStateMachine. I have noticed that it seems signals are always handled before events posted via postEvent. For example, if an event is posted while a state is in an onEntry handler that emits a signal the state machine processes, the state machine will always process the signal first before the posted event, even if the event is posted before the signal is fired.

    Is this behavior expected? Can I rely on it always being true?


  • @AccWhid said in QStateMachine Order of Event Handling:

    Is this behavior expected?

    Yes, if sender and receiver in signal/slot are on the same thread (Qt::DirectConnection), emitting a signal is equivalent to calling directly the slots in the order they where connected. Events are processed when the program handles control back to the event loop (or QCoreApplication::processEvents() is called).
    signal/slot connected in different threads or with Qt::QueuedConnection will be delayed at the same time as events are processed.

    Can I rely on it always being true?

    You can but it's not a super solid design choice

  • That's what I thought, but I wasn't sure if the state machine might be re-posting signals as events on the state machine's event queue that would then be handled.

Log in to reply

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