Solved Why does QStateMachine not stop?
-
In the following code,
QStateMachine::stop()
does not stop the state machine:self.state_mc = QStateMachine() self.state_mc.start() # state machine starts ... if self.state_mc.isRunning(): # yes, this returns that it is running self.state_mc.stop() # this is supposed to stop it # HOWEVER, at this line `self.state_mc.isRunning()` *still* returns True ... # on next line, debug window shows warning `QStateMachine::start(): already running` self.state_mc.start()
Note that there is no event loop run after the
stop()
and before the nextstart()
. Is this the cause of the behaviour? I want to "reset" the state machine, so I stop, alter and then restart it. What should I do? -
Yes. Eventloop should be running.
-
Yes. Eventloop should be running.
-
@dheerendra
Thank you for replying.Hmmm. I don't have an event loop here, and I don't want to call one. The proposed call to
stop()
and then laterstart()
again in one function surrounds code whose job is to reset theQStateMachine
, like clearing out its states and recreating them anew. I thought it would be a good idea to stop and restart. I guess I'll give it a go without stop/start, and hope that will be OK?