Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-92108

[SCXML] Method 'submitEvent(const QString &, const QVariant &data)' always pass variant data as string to state machine

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • 5.15
    • State Machine: SCXML
    • None
    • All

      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();
      }
      

        1. image-2021-03-24-18-01-57-686.png
          10 kB
          Alex Zhornyak
        2. VariantBug.gif
          37 kB
          Alex Zhornyak
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            ulherman Ulf Hermann
            alexzhornyak Alex Zhornyak
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes