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. How to use cplusplus data model with QScxmlStateMachine
Forum Updated to NodeBB v4.3 + New Features

How to use cplusplus data model with QScxmlStateMachine

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 1.3k Views 1 Watching
  • 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.
  • N Offline
    N Offline
    nurdglaw
    wrote on last edited by
    #1

    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.

    N 1 Reply Last reply
    0
    • N nurdglaw

      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.

      N Offline
      N Offline
      nurdglaw
      wrote on last edited by
      #2

      Anybody?

      Is there a Qt developer in the house?

      jsulmJ 1 Reply Last reply
      0
      • N nurdglaw

        Anybody?

        Is there a Qt developer in the house?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        N 1 Reply Last reply
        0
        • jsulmJ jsulm

          @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.

          N Offline
          N Offline
          nurdglaw
          wrote on last edited by
          #4

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

          Where is it?

          jsulmJ 1 Reply Last reply
          0
          • M Offline
            M Offline
            MrShawn
            wrote on last edited by MrShawn
            #5

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

            N 1 Reply Last reply
            0
            • N nurdglaw

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

              Where is it?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @nurdglaw http://lists.qt-project.org/mailman/listinfo

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              N 1 Reply Last reply
              0
              • M MrShawn

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

                N Offline
                N Offline
                nurdglaw
                wrote on last edited by
                #7

                @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.

                1 Reply Last reply
                0
                • jsulmJ jsulm

                  @nurdglaw http://lists.qt-project.org/mailman/listinfo

                  N Offline
                  N Offline
                  nurdglaw
                  wrote on last edited by
                  #8

                  @jsulm Thanks.

                  1 Reply Last reply
                  0
                  • larry104L Offline
                    larry104L Offline
                    larry104
                    wrote on last edited by
                    #9

                    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>.

                    1 Reply Last reply
                    0

                    • Login

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