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. qtscxml: connect to signals
Forum Updated to NodeBB v4.3 + New Features

qtscxml: connect to signals

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.6k 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.
  • larry104L Offline
    larry104L Offline
    larry104
    wrote on last edited by
    #1

    I'm playing with qtscxml and I'm running into a problem - here is a simple state machine

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- enable-qt-mode: yes -->
    <scxml xmlns="http://www.w3.org/2005/07/scxml" xmlns:qt="http://theqtcompany.com/scxml/2015/06/" version="1.0" name="KeyboardStateMachine" initial="s1">

    <state id="s1">
        <onentry>
          <log expr="Now in s1" />
          <send event="enter_state1"/>
        </onentry>
        <transition event="key_pressed" target="s2"/>
    </state>
    <state id="s2">
        <onentry>
            <log expr="Now in s2" />
            <send event="enter_state2"/>
        </onentry>
        <transition event="key_released" target="s1"/>
    </state>
    

    </scxml>

    I want to connect to the signals enter_state1 and enter_state2 on the c++ side.

    QObject::connect(machine, SIGNAL(enter_state1()), this, SLOT(keyLedOff()));
    QObject::connect(machine, SIGNAL(enter_state1()), this, SLOT(lkeyLedOon()));

    but I get an error: QObject::connect: No such signal KeyboardStateMachine::enter_state1()

    What I'm I doing wrong here?

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

      @larry104 said:
      Hi
      The normal cause for this error is
      1: forgot
      Q_OBJECT macro in a QObject subclass ( your KeyboardStateMachine)

      2:
      Using visual studio and qmake/moc.exe is not run.

      Update:
      Did you check the files generated by
      qscxmlc
      that they do in fact contain such signals?

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

        1: is done
        #ifndef KEYBOARD_H
        #define KEYBOARD_H

        #include <QObject>
        #include <QHash>
        #include <QColor>
        #include <QDebug>
        #include "statemachine.h"

        class Keyboard : public QObject
        {
        Q_OBJECT

        public:
        explicit Keyboard(QHash<QString, QObject*> keys, QObject *parent = 0);

        signals:

        public slots:
        void ledOn();
        void ledOff();
        void keyPressed();
        void keyReleased();

        private:
        KeyboardStateMachine m_machine;
        QHash<QString, QObject
        > m_keys;
        };

        #endif // KEYBOARD_H

        2: I'm using qt5.7.0 on ubuntu with qtcreator. My .pro file looks like this:

        QT += qml quick scxml
        CONFIG += c++11
        SOURCES += main.cpp
        keyboard.cpp
        STATECHARTS = statemachine.scxml
        load(qscxmlc)
        RESOURCES += qml.qrc
        QML_IMPORT_PATH =
        include(deployment.pri)
        HEADERS +=
        keyboard.h

        It's interesting the statmachine.h gets only created if I run the compile from commandline. How can I tell qtcreator to run the compile of the statemachine so it finds the .h file - but that's a different issue.

        But to answer the question the statemachine.h file create when calling qscxmlc statemachine.scxml does not contain the signals -
        qscxmlc --version is: qscxmlc 1 (Qt 5.7.0)

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

          Hmm, seems to follow the docs closely so should be ok.
          STATECHARTS should make qmake run tool. ?

          I wonder how connect can possible work then if no signals generated. are they somehow exported from QML?

          Sorry, i have never used this new module so Im afraid we must
          hope for others to have better suggestions :)

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

            I found the problem - to create a qt signal I need to set the following:

            <send type="qt:signal" event="enter_state1"/>

            mrjjM 1 Reply Last reply
            2
            • larry104L larry104

              I found the problem - to create a qt signal I need to set the following:

              <send type="qt:signal" event="enter_state1"/>

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @larry104
              good found :)

              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