How to use cplusplus data model with QScxmlStateMachine



  • Hi,

    I am using a state machine from C++. The state machine must emit messages in several places, so the .scxml files include several fragments like this:

    <state id="A">
        <transition event="AtoB" target="B">
            <send event="transitioningFromAToB">
        </transition>
    </state>
    

    I'd like to change this to have a single "transitioning" message with parameters, something like:

    <state id="A">
        <transition event="AtoB" target="B">
            <send event="transitioning">
                <param name="from" expr="A" />
                <param name="to" expr="B" />
            </send>
        </transition>
    </state>
    

    Please can someone show me how to write a class derived from QScxmlDataModel to impliment this?

    I've tried adding 'datamodel="cplusplus:simpleDataModel:simpledatamodel.h"' to the <scxml> node, with a simpleDataModel class derived from QScxmlDataModel and my program crashes when I try to start my first machine.

    Thanks.

    Note: I wrote the scxml fragments above while writing this post, to try to clarify what I am trying to do. I will be writing the .scxml file using qtcreator in design mode. Please don't get hung up over any errors I've made in syntax or semantics.



  • Anybody?

    Is there a Qt developer in the house?


  • Moderators

    @nurdglaw You need to understand that this is user forum and people here are helping in their own free time without being paid. If somebody reads your question and knows the answer he/she will answer.
    If you want to contact Qt developers (I mean those developing qt itself) you should go to Qt mailing list.



  • @jsulm Thanks for the response. I'm happy to go to the mailing list.

    Where is it?



  • Are you trying to get A and B into c++?


  • Moderators



  • @MrShawn Essentially yes, I think. There's lots of things I'd like to do within the state machine that I currently do in a C++ class that wraps it. I'm happy that once I can do anything that involves a C++ data model, I'll be able to do everything (if not, I know where to go for help :-)) and I think the simplest will be adding parameters to the output messages. Unfortunately I can't currently manage even that...

    As I say above, even my first tiny step toward using a data model has faltered.



  • @jsulm Thanks.



  • You can just send signals from and to your state machine.

    scxml code:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- enable-qt-mode: yes -->
    <scxml
    ....
    
    <send type="qt:signal" event="transitioning"><param name="from" expr="A" />
                <param name="to" expr="B" />
            </send>
    
    

    c++ code:

        QObject::connect(m_stateMachine, SIGNAL(transitioning(QVariant)), this, SLOT(transitioning(QVariant)));
    
    

    All <param> children will be placed inside a QMap<QString, QVariant>.


Log in to reply
 

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