Qt SCXML Invoke Example (Dynamic)

Image non disponible

Invoke Example (Dynamic) demonstrates how to use the <invoke> element with generated nested state-machines, where the SCXML file is dynamically loaded. The <invoke> element is used to create an instance of an external service.

Running the Example

To run the example from Qt Creator, open the Welcome mode and select the example from Examples. For more information, visit Building and Running an Example.

Invoking the State Machine

In statemachine.scxml, we specify a state machine with the name Directions of type http://www.w3.org/TR/scxml/ to invoke:

 
Sélectionnez
&lt;scxml
    xmlns="http://www.w3.org/2005/07/scxml"
    version="1.0"
    name="Directions"
    initial="anyplace"
&gt;
    &lt;state id="anyplace"&gt;
        &lt;transition event="goNowhere" target="nowhere"/&gt;
        &lt;transition event="goSomewhere" target="somewhere"/&gt;

        &lt;state id="nowhere"/&gt;
        &lt;state id="somewhere"&gt;
            &lt;invoke type="http://www.w3.org/TR/scxml/"&gt;
                &lt;content&gt;
                    &lt;scxml name="anywhere" version="1.0"&gt;
                        &lt;state id="here"&gt;
                            &lt;transition event="goThere" target="there"/&gt;
                        &lt;/state&gt;
                        &lt;state id="there"&gt;
                            &lt;transition event="goHere" target="here"/&gt;
                        &lt;/state&gt;
                    &lt;/scxml&gt;
                &lt;/content&gt;
            &lt;/invoke&gt;
        &lt;/state&gt;
    &lt;/state&gt;
&lt;/scxml&gt;

Dynamically Loading the State Machine

We link against the Qt SCXML module by adding the following line to the invoke-dynamic.pro file:

 
Sélectionnez
QT += qml scxml

We dynamically create the state machine, as follows:

 
Sélectionnez
import QtScxml 5.8

MainView {
    stateMachine: directions.stateMachine

    StateMachineLoader {
        id: directions
        source: "qrc:///statemachine.scxml"
    }

List of Files

Files:

List of Files