Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QSCXML and the In() Predicate
Forum Updated to NodeBB v4.3 + New Features

[Solved] QSCXML and the In() Predicate

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tjp5
    wrote on last edited by
    #1

    I'm creating a Qt application that utilizes qscxml and state machines. Certain transitions within my state machine need to fire based upon the current substate of a parallel state, so I have set the cond = "In('state')" on those transitions. Using logging within my state machine, I have confirmed the state that's being referenced is active, however the condition always resolves to be false. Stepping through the code I see that the isInState function within qscxml.cpp always returns false.

    @
    static QScriptValue isInState(QScriptContext context, QScriptEngine engine)
    {
    QScxml
    scxml = qobject_cast<QScxml
    >(context->thisObject().toQObject());
    if (scxml) {
    if (context->argumentCount() > 0) {
    QString name = context->argument(0).toString();
    if (!name.isEmpty()) {
    QSet<QAbstractState*> cfg = scxml->configuration();
    foreach (QAbstractState* st, cfg) {
    if (st->objectName() == name)
    return qScriptValueFromValue<bool>(engine,true);
    }
    }
    }
    }
    return qScriptValueFromValue<bool>(engine,false);
    }
    @

    The scxml pointer is always null. A very simple concept of my scxml is as follows:

    @
    <parallel id = "main">
    <state id = "process1" initial="init1">
    <state id="init1">
    <transition cond = "In('init2')" target = "destination"/>
    </state>
    <state id="destination">
    </state>
    </state>
    <state id = "process2" initial="init2">
    <state id="init2">
    </state>
    </state>
    </parallel>
    @

    The qscxml class seems to recognize In() and does at least attempt to evaluate. Is it not possible to use the In() predicate without modifying the qscxml class, or do I have an error in how I am attempting to use In()?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tjp5
      wrote on last edited by
      #2

      I believe I figured out a solution. The In() predicate is part of the script engine's global object, making it accessible from the script code. Since the object obtained from QScriptContext was the global object, the cast could not be made. I modified the cast to instead be:

      @
      QScxml* scxml = qobject_cast<QScxml*>(context->engine()->globalObject().property("scxml").toQObject());
      @

      Which retrieves the QScriptValue containing the pointer to the script engine, allowing the cast to work. Now my state machine is performing as expected.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved