Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Why does QStateMachine not stop?

    General and Desktop
    2
    3
    326
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JonB
      JonB last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • dheerendra
        dheerendra Qt Champions 2022 last edited by

        Yes. Eventloop should be running.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        JonB 1 Reply Last reply Reply Quote 1
        • dheerendra
          dheerendra Qt Champions 2022 last edited by

          Yes. Eventloop should be running.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          JonB 1 Reply Last reply Reply Quote 1
          • JonB
            JonB @dheerendra last edited by JonB

            @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?

            1 Reply Last reply Reply Quote 0
            • First post
              Last post