Managing events of a QScxmlStateMachine
-
Hi!
Here's my problem: the events sent by submitEvent("myTransition") are not executed immediately, but just after the client code and just before the application gives the hand to the user.
The problem is I test the active state just after submitEvent("myTransition").I believe that the event sent by submitEvent("myTransition") is placed on the main event loop queue list and treated just before waiting a new user event.
To solve this problem I run this command just after submitEvent():
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
But the Qt documentation warns that it's not recommended to use it, so I'm looking for a another solution.I've found in the documentation page ScxmlStateMachine QML Type, at the end of the page, another use of submitEvent(event). The doc tells that this method Submits the SCXML event event to the internal or external event queue depending on the priority of the event..
It looks interesting so I looked for elements for these event queues and how giving priority to an event, but I didn't find anything, even in the QScxmlEvent doc.So, can it be a solution to my problem? If yes, how to do this?
Thanks!
Max -
Hi!
Here's my problem: the events sent by submitEvent("myTransition") are not executed immediately, but just after the client code and just before the application gives the hand to the user.
The problem is I test the active state just after submitEvent("myTransition").I believe that the event sent by submitEvent("myTransition") is placed on the main event loop queue list and treated just before waiting a new user event.
To solve this problem I run this command just after submitEvent():
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
But the Qt documentation warns that it's not recommended to use it, so I'm looking for a another solution.I've found in the documentation page ScxmlStateMachine QML Type, at the end of the page, another use of submitEvent(event). The doc tells that this method Submits the SCXML event event to the internal or external event queue depending on the priority of the event..
It looks interesting so I looked for elements for these event queues and how giving priority to an event, but I didn't find anything, even in the QScxmlEvent doc.So, can it be a solution to my problem? If yes, how to do this?
Thanks!
Max@Max said in Managing events of a QScxmlStateMachine:
The problem is I test the active state just after submitEvent("myTransition").
Why? This is not correct in an event driven application.
What are you trying to achieve? -
Hello!
It's the case: when a QTextEdit is filled it sends a signal. In the corresponding slot I call a submitEvent() and then I test the state of the machine. If the machine is in a particular state, I modify the style of another widget before the hand is sent back to the user.
But without the QApplication::processEvents() after the submitEvent() the state of the machine doesn't change immediately and the style of the widget is not set conveniently. -
Hello!
It's the case: when a QTextEdit is filled it sends a signal. In the corresponding slot I call a submitEvent() and then I test the state of the machine. If the machine is in a particular state, I modify the style of another widget before the hand is sent back to the user.
But without the QApplication::processEvents() after the submitEvent() the state of the machine doesn't change immediately and the style of the widget is not set conveniently.@Max said in Managing events of a QScxmlStateMachine:
If the machine is in a particular state, I modify the style of another widget before the hand is sent back to the user
In an event driven application you would react on state machine change instead of posting an event and expecting it to take effect immediately. You should rethink your design.