"entered" signal in Qstate is NOT called at fist
-
I encountered one strange problem on QState. Firstly, please allow me to describe our current code structure . We have one QTimer to call one function named “OnTickTimer” each 500 ms. And the code in “OnTickTimer” is like below code snippet.
void onTickTimer()
{
switch (m_currentState) //I made simplification here – INIT, IDLE and RUN are all QState objects.
{
case INIT:
func1();
break;
case IDLE:
func2();
break;
case RUN:
func3();
break;
default:
break;
};
}Supposing we use the “entered()” signal during state transition as below line:
QOjbect::connect(RUN, entered(), this, OnRun());In most cases, the slot “OnRun” was called before “func3()”, which was what we expected. But unfortunately, that was not true all the time – sometimes “func3()” could also run before “OnRun()”.
-
Hi,
Can you explain the use case of that architecture ? You can't expect a timer and an asynchronous system like a state machine to always have the same timed behavior.