Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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 next start(). 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?


  • Qt Champions 2017

    Yes. Eventloop should be running.


  • Qt Champions 2017

    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 later start() again in one function surrounds code whose job is to reset the QStateMachine, 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?


Log in to reply