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? -
I know it's been a while, but for the record: if you call stop() and afterwards connect the stopped() signal of the statemachine to the start() slot you're good to go.
Like this:
connect(machineName, &QStateMachine::stopped(), machineName, &QStateMachine::start); -
A Anonimista referenced this topic on