Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. QScxmlStateMachine targetless transition
QtWS25 Last Chance

QScxmlStateMachine targetless transition

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
6 Posts 3 Posters 1.2k Views
  • 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.
  • D Offline
    D Offline
    d_h_mcinnes
    wrote on last edited by d_h_mcinnes
    #1

    Hi

    I am experimenting with the QScxmlStateMachine class. Is it possible to add a targetless transition to states in my state machine? How do I do it?

    My use case is, I have a C++ app, with 2 states, "normalmode" and "crazymode". I have an event "received_packet_blah", I want to handle this event differently in my two states. I don't want this event to cause a state change.

    I can see how to do this with QStateMachine (http://doc.qt.io/qt-5/statemachine-api.html), which has a good description, but not for QScxmlStateMachines. I don't really understand the relationship between QStateMachines and QScxmlStateMachines - are they totally unrelated?

    I suppose I could call QScxmlStateMachine::connectToEvent("received_packet_blah", SLOT(rx_blah));, and inside rx_blah() I could find out whether I was in crazymode or normalmode, and call the relevant event handler, but it seems clumsy, and I get the feeling I am trying to do this the wrong way.

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Yes both are unrelated, QStateMachine was created a long time before QScxmlStateMachine and they do not share implementation nor logic as the later is based on the SCXML Specification.

      Can you show how you defined your state machine ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        Yes both are unrelated, QStateMachine was created a long time before QScxmlStateMachine and they do not share implementation nor logic as the later is based on the SCXML Specification.

        Can you show how you defined your state machine ?

        D Offline
        D Offline
        d_h_mcinnes
        wrote on last edited by d_h_mcinnes
        #3

        @SGaist, I don't have sufficient privileges to attach files, so I have copy and pasted below:

        #include <QGuiApplication>
        #include <QQmlApplicationEngine>
        #include <QScxmlStateMachine>
        #include "eventhandler.h"
        #include "hsm.h"

        int main(int argc, char *argv[])
        {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);

        QQmlApplicationEngine engine;
        engine.load(QUrl(QLatin1String("qrc:/main.qml")));
        if (engine.rootObjects().isEmpty())
            return -1;
        
        EventHandler eventhandler;
        hsm statemachine;
        bool retval = static_cast<bool>(statemachine.connectToState("normal_mode", &eventhandler, SLOT(On_enter_state_normal_mode(bool))));
        retval &= static_cast<bool>(statemachine.connectToState("crazy_mode", &eventhandler, SLOT(On_enter_state_crazy_mode(bool))));
        retval &= static_cast<bool>(statemachine.connectToEvent("rx_packet_blah", &eventhandler, SLOT(On_event_rx_packet_blah())));
        
        statemachine.start();
        
        statemachine.submitEvent("rx_packet_blah");
        
        statemachine.submitEvent("enter_crazy_mode");
        
        statemachine.submitEvent("rx_packet_blah");
        
        return app.exec();
        

        }

        <?xml version="1.0" encoding="UTF-8"?>
        <scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" binding="early" name="hsm" qt:editorversion="4.4.1" xmlns:qt="http://www.qt.io/2015/02/scxml-ext">
        <state id="wrapper">
        <qt:editorinfo scenegeometry="172.33;289.58;52.52;239.58;711.81;286" geometry="172.33;289.58;-119.81;-50;711.81;286"/>
        <state id="normal_mode">
        <qt:editorinfo scenegeometry="259;398.15;199;317.02;120;131.13" geometry="86.67;108.57;-60;-81.13;120;131.13"/>
        <transition type="external" event="enter_crazy_mode" target="crazy_mode"/>
        </state>
        <state id="crazy_mode">
        <qt:editorinfo scenegeometry="525.13;382.58;465.13;332.58;120;100" geometry="352.80;93;-60;-50;120;100"/>
        <transition type="external" event="enter_normal_mode" target="normal_mode">
        <qt:editorinfo endTargetFactors="75.48;76.19"/>
        </transition>
        </state>
        </state>
        </scxml>

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The QtScxml Sudoku example mentions a target less transition so it might give you the information you are missing.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          D 1 Reply Last reply
          3
          • SGaistS SGaist

            The QtScxml Sudoku example mentions a target less transition so it might give you the information you are missing.

            D Offline
            D Offline
            d_h_mcinnes
            wrote on last edited by
            #5

            @SGaist , thank you very much. This is exactly what I was looking for.

            aha_1980A 1 Reply Last reply
            1
            • D d_h_mcinnes

              @SGaist , thank you very much. This is exactly what I was looking for.

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @d_h_mcinnes then please mark this topic as SOLVED. thanks

              Qt has to stay free or it will die.

              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