-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.15
-
None
Method submitEvent(const QString &, const QVariant &data) always pass numbers in Variant data as string to state machine. But if we pass numbers inside of VariantMap data it works properly.
1) _event.data.x - will come to statemachine as number
QVariantMap data; data.insert("x", 1); machine->submitEvent("test", data);
2) _event.data - will come to statemachine as string
QVariant data = 1;
machine->submitEvent("test", data);
Minimal example
#include <QCoreApplication> #include <QScxmlStateMachine> #include <QBuffer> #include <QLoggingCategory> namespace Scxml { static const char *chScxml = "<scxml datamodel=\"ecmascript\" initial=\"checkVariantMap\" name=\"ScxmlCheckVariant\" version=\"1.0\" xmlns=\"http://www.w3.org/2005/07/scxml\">" " <state id=\"checkVariantMap\">" " <transition cond=\"_event.data.x === 1\" event=\"test\" target=\"checkVariant\"/>" " <transition event=\"test\" target=\"fail\"/>" " </state>" " <state id=\"checkVariant\">" " <transition cond=\"_event.data === 1\" event=\"test\" target=\"pass\"/>" " <transition event=\"test\" target=\"fail\"/>" " </state>" " <final id=\"pass\"/>" " <final id=\"fail\"/>" "</scxml>"; } // end namespace: Scxml int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QBuffer buffer; buffer.open(QBuffer::ReadWrite); buffer.write(Scxml::chScxml); buffer.seek(0); auto machine = QScxmlStateMachine::fromData(&buffer); for (auto it : machine->stateNames(false)) { machine->connectToState(it, [=](const bool active) { qDebug() << (active ? "Enter:" : "Exit:") << it; if (active) { if (it=="pass") { qInfo() << "PASS!"; QCoreApplication::exit(0); } else if (it=="fail") { qCritical() << "FAIL!"; QCoreApplication::exit(0); } } }); } machine->start(); { QVariantMap data; data.insert("x", 1); machine->submitEvent("test", data); } { QVariant data = 1; machine->submitEvent("test", data); } return a.exec(); }