Problem with QScxmlStateMachine and boolean data type in SCXML transition condition
-
Hi,
i have the problem that if there is a boolean data type in the condition part of the scxml file, the QScxmlStateMachine::submitEvent(const QString &eventName, const QVariant &data) function does not work as i expect.
This is my simple scxml file
<?xml version="1.0" encoding="UTF-8"?> <scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" datamodel="ecmascript" name="default" initial="ViewA"> <state id="MainWindow"> <state id="ViewA"> <transition event="switch1" cond="_event.data == true" target="ViewB"/> <transition event="switch1" cond="_event.data == false" target="ViewC"/> </state> <state id="ViewB"> <transition event="switch2" cond="_event.data == false" target="ViewA"/> <transition event="switch2" cond="_event.data == true" target="ViewC"/> </state> <state id="ViewC"> <transition event="switch3" cond="_event.data == true" target="ViewA"/> <transition event="switch3" cond="_event.data == false" target="ViewB"/> </state> </state> </scxml>
So it's all about this part:
cond="_event.data == true"
When I call
submitEvent("switch1", true)
the view is not changing.
But, if I put there an integer, for example
cond="_event.data == 5"
the view changes after calling:
submitEvent("switch1", 5)
Does somebody has any idea?
Thank you! -
Hi,
i have the problem that if there is a boolean data type in the condition part of the scxml file, the QScxmlStateMachine::submitEvent(const QString &eventName, const QVariant &data) function does not work as i expect.
This is my simple scxml file
<?xml version="1.0" encoding="UTF-8"?> <scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" datamodel="ecmascript" name="default" initial="ViewA"> <state id="MainWindow"> <state id="ViewA"> <transition event="switch1" cond="_event.data == true" target="ViewB"/> <transition event="switch1" cond="_event.data == false" target="ViewC"/> </state> <state id="ViewB"> <transition event="switch2" cond="_event.data == false" target="ViewA"/> <transition event="switch2" cond="_event.data == true" target="ViewC"/> </state> <state id="ViewC"> <transition event="switch3" cond="_event.data == true" target="ViewA"/> <transition event="switch3" cond="_event.data == false" target="ViewB"/> </state> </state> </scxml>
So it's all about this part:
cond="_event.data == true"
When I call
submitEvent("switch1", true)
the view is not changing.
But, if I put there an integer, for example
cond="_event.data == 5"
the view changes after calling:
submitEvent("switch1", 5)
Does somebody has any idea?
Thank you!@Mr_Gruber said in Problem with QScxmlStateMachine and boolean data type in SCXML transition condition:
scxml
What if you use the approach suggested in this answer (part #2)?
Simply checking for 0 or 1 in your SCXML "cond" property -
Thank you for your reply. By the way, I'm using QT 5.15.2
Unfortunately it doesn't work with 0 and 1. It works if I write it as a stringcond="_event.data == 'true'"
even if I leave the boolean in the code.
And there is one more thing, my scxml file is auto-generated by a statechart tool (yakindu), so the program should work with this scxml syntax.