Discussion:
QT SCXML: How to access Event parameter from State?
(too old to reply)
Jonathan Fan
2018-03-05 23:20:42 UTC
Permalink
Raw Message
Hi,

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

SCXML:

<state id="state1">
<transition type="external" event="myEvent" target="state2"/>
</state>
<state id="state2">
<!-- ... -->
</state>
<state id="state5">
<transition type="external" event="myEvent" target="state6"/>
</state>
c++:
QVariantMap data;
data.insert(QStringLiteral("param1"), 1);
data.insert(QStringLiteral("param2"), 2);
stateMachine->submitEvent("myEvent", data);
stateMachine->connectToEvent("myEvent", [this](const QScxmlEvent &
event){
// 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
event.
});
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.html#onEntry

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 in connectToEvent, we do
not know at this point whether 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"?
Best,
Jonathan

Loading...