Important: Please read the Qt Code of Conduct -

QStateMachine, scxml, custom states questions

  • I am getting into the state machine framework and I have a couple questions.

    From what I've read the State machine runs in its own event loop, to make use of that I need a custom state (inheret from QState) and overwrite on entry method. Is this correct? Also can I implement a custom state like that using scxml? The scxml editor is very nice for quickly defining the state machine structure but I feel I am losing a lot of potential control over making the state machine programatically. In order to get c++ functionality into my state machine I connect event signals and slots, in which case the code is ran in my ui event loop - not what I want (this is using the scxml state machine that was generated).

    I tried looking around to find how to work with the qt state machine, I saw a lot of really simple examples but everything focuses on transitions and different state types. The best example of doing some work doesn't make use of scxml (it says inherent the QState and override which I don't believe I can do with the scxml generated state machine). If anyone has some pointers on how to best use the state machine and implementing c++ code i would be glad to hear it. I need to use c++ for a few reasons , DB connectivity, and hardware interfacing.


  • I'm starting down the Scxml road. It's unfortunate you never got answers to your questions here, but did you ever get some answers elsewhere or figure things out to the point you're still on this road?

  • I don't tend to use the SCXML anymore. I just use the C++ framework and build my state machine in code. I tend to inherit QState with a BaseState class implementation that I can used to define base functionality with certain signals / slots and usually have access to a shared pointer which contains state machine data. From there I inherit the BaseState and apply the state specific logic.

    For prototyping state machine structure I tend to use the app which is a little less clunky than the SCXML editor.

Log in to reply