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

Using QScxmlStateMachine data model QML



  • Hi

    I found an example of using Scxml in QML here: https://doc.qt.io/qt-5/qtscxml-instantiating-state-machines.html

    The example is great, it lets you do the following:

    import MyStateMachine 1.0
    
    MyStateMachine {
        id: stateMachine
    }
    
    Light {
        id: greenLight
        color: "green"
        visible: stateMachine.green // this is what I want to do, toggle visibility based on whether I am in a certain state
    }
    
    

    ... but it only seems to work if you instantiate your state machine in QML.

    In my case, I have instantiated the state machine in C++, and am having trouble making the state machine properties visible to my QML code. The generated C++ code contains a Q_PROPERTY(bool some_state), but does not include getters, setters, or 'changed' signals for each of the states. So, when some event happens, the C++ state machine enters the correct state, but the QML code doesn't receive any signal, and my green light never turns on.

    Is there some way I can make my C++ Qscxml state machine transitions visible in QML land?


  • Lifetime Qt Champion

    Hi,

    Please show the code you use. Otherwise it's impossible to start helping you.


Log in to reply