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?
Thanks!
-
@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 (orQCoreApplication::processEvents()
is called).
signal/slot connected in different threads or withQt::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