[Interest] QT SCXML: How to access Event parameter from State?

Jonathan Fan jonathan.fan at gmail.com
Fri Mar 16 18:16:52 CET 2018


We are in the process of migrating from QStateMachine to QT SCXML on QT
For example, we have the following stateMachine where the same event drives
multiple transitions in the stateMachine,
with C++ implementing the programmatic hooks like connectToState and


<state id="state1">
    <transition type="external" event="myEvent" target="state2"/>
<state id="state2">
    <!-- ... -->
<state id="state5">
    <transition type="external" event="myEvent" target="state6"/>
    QVariantMap data;
    data.insert(QStringLiteral("param1"), 1);
    data.insert(QStringLiteral("param2"), 2);
    stateMachine->submitEvent("myEvent", data);
    stateMachine->connectToEvent("myEvent", [this](const QScxmlEvent &
        // We have access through event's parameters. however, it is
technically encapsulated from us
        // which transitions, if any, are going to be triggered by this
    stateMachine->connectToState("state1", [this](bool active) {
        if (active){
            // We want to access the data from the incoming event.

    stateMachine->connectToState("state5", [this](bool active) {
        if (active){
            // We want to access the data from the incoming event.
The event is submitted with parameters, and we want to be able to access
the parameters Events from a state, like how in QStateMachine where we can
access event parameter through extending http://doc.qt.io/qt-5/qstate.

SCXML Events is a standalone entity (orthogonal to States), and events may
or may not trigger transitions.
Although we do have access to the event parameter at connectToEvent, we do
not know at this point which transitions are going to be triggered and so
it does not seem to be the right place to handle any State specific logic.
In the example above, how would we get access to Event parameter for
"state1" and "state5"?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180316/0e3d933c/attachment.html>

More information about the Interest mailing list