Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why does QStateMachine not stop?

Why does QStateMachine not stop?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 767 Views
  • 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.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #1

    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
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Yes. Eventloop should be running.

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

      JonBJ 1 Reply Last reply
      1
      • dheerendraD dheerendra

        Yes. Eventloop should be running.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @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
        0
        • J Offline
          J Offline
          Jackar710
          wrote on last edited by
          #4

          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);

          1 Reply Last reply
          0
          • A Anonimista referenced this topic on

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved