qtscxml: connect to signals



  • 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?


  • Qt Champions 2016

    @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: 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)


  • Qt Champions 2016

    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 :)



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

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


  • Qt Champions 2016

    @larry104
    good found :)


Log in to reply
 

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