Problems with QStateMachine?

  • My application has more than one instances of a Widgets UI at runtime. Every instance creates its own statemachine during initialization.
    MyStateMachine * fsm = new MyStateMachine();
    During development, I just use QTest::qWait(1000) simulating an action at every state.

    However the statemachine doesn't run smoothly:

    1. If I click the graphic interface among the instances every fast. I get the following error:
      QStateMachine::postEvent: cannot post event when the state machine is not running
      As a consequence, that statemachine hangs. It's interesting, that it's happening always shortly after the start of the statemachine.

    My guess: the instance losts perhaps its focus, as a result, the defined connects between signal and slots don't work any more. How could I improve it? Any experience from you?

    1. Some statemachines get suddenly stuck, wait more than specified 1 second in ist progress.
      Maybe the thread for QTest::qWait doesn't work properly. Do you have any better method make a unblocked delay for a couple of seconds?

    Many thanks in advance for your insights.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    QTest::qWait is for testing purpose only so you should not use it in production code. If you need a delay between two state; did you try a QTimer + QSignalTransition combo ?

    Otherwise, you'll have to give more details about your state machine

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.