ScxmlStateMachine QML Type | Qt SCXML | Qt 6.11.1
Description: Provides an interface to the state machines created from SCXML files.

- Qt 6.11
- Qt SCXML
- QML Types
- ScxmlStateMachine
- Qt 6.11.1 Reference Documentation

# ScxmlStateMachine QML Type

Provides an interface to the state machines created from SCXML files. More...

Import Statement: | `import QtScxml 6.11`
In C++: | QScxmlStateMachine

- List of all members, including inherited members

## Properties

- dataModel : ScxmlDataModel
- initialValues : var
- initialized : bool
- invoked : bool
- invokedServices : list
- loader : Loader
- name : string
- parseErrors : var
- running : bool
- sessionId : string

## Signals

- finished()
- log(string label, string msg)
- reachedStableState()

## Methods

- list<string> activeStateNames(bool compress)
- void cancelDelayedEvent(string sendId)
- bool init()
- bool isActive(string scxmlStateName)
- bool isDispatchableTarget(string target)
- void start()
- list<string> stateNames(bool compress)
- void stop()
- void submitEvent(event)
- void submitEvent(string eventName, var data)

## Detailed Description

The ScxmlStateMachine type is an implementation of the State Chart XML (SCXML).

All states that are defined in the SCXML file are accessible as properties of this type. These properties are boolean values and indicate whether the state is active or inactive.

## Property Documentation

### dataModel : ScxmlDataModel

The data model to be used for this state machine.

SCXML data models are described in SCXML Specification - 5 Data Model and Data Manipulation. For more information about supported data models, see SCXML Compliance.

Changing the data model when the state machine has been initialized is not specified in the SCXML standard and leads to undefined behavior.

See also QScxmlDataModel, QScxmlNullDataModel, and QScxmlCppDataModel.

### initialValues : var

The initial values to be used for setting up the data model.

### initialized : bool `[read-only]`

This read-only property is set to `true` if the state machine has been initialized, `false` otherwise.

### invoked : bool `[read-only]`

Whether the state machine was invoked from an outer state machine.

This read-only property is set to `true` when the state machine was started as a service with the `<invoke>` element, `false` otherwise.

### invokedServices : list `[read-only]`

A list of SCXML services that were invoked from the main state machine (possibly recursively).

### loader : Loader

The loader that is currently used to resolve and load URIs for the state machine.

### name : string `[read-only]`

The name of the state machine as set by the name attribute of the `<scxml>` tag.

### parseErrors : var `[read-only]`

The list of parse errors that occurred while creating a state machine from an SCXML file.

### running : bool

The running state of this state machine.

### sessionId : string `[read-only]`

The session ID of the current state machine.

The session ID is used for message routing between parent and child state machines. If a state machine is started by an `<invoke>` element, any event it sends will have the `invokeid` field set to the session ID. The state machine will use the origin of an event (which is set by the target or targetexpr attribute in a `<send>` element) to dispatch messages to the correct child state machine.

## Signal Documentation

### finished()

This signal is emitted when the state machine reaches a top-level final state.

The corresponding signal handler is `onFinished()`.

Note: The corresponding handler is `onFinished`.

### log(string label, string msg)

This signal is emitted if a `<log>` tag is used in the SCXML. label is the value of the label attribute of the `<log>` tag. msg is the value of the evaluated expr attribute of the `<log>` tag. If there is no expr attribute, a null string will be returned.

The corresponding signal handler is `onLog()`.

Note: The corresponding handler is `onLog`.

### reachedStableState()

This signal is emitted when the event queue is empty at the end of a macro step or when a final state is reached.

The corresponding signal handler is `onreachedStableState()`.

Note: The corresponding handler is `onReachedStableState`.

## Method Documentation

### list<string> activeStateNames(bool compress)

Retrieves a list of state names of all active states.

When a state is active, all its parent states are active by definition. When compress is `true` (the default), the parent states are filtered out and only the leaf states are returned. When it is `false`, the full list of active states is returned.

### void cancelDelayedEvent(string sendId)

Cancels a delayed event with the specified sendId.

### bool init()

Initializes the state machine by setting the initial values for `<data>` elements and executing any `<script>` tags of the `<scxml>` tag. The initial data values are taken from the initialValues property.

Returns `false` if parse errors occur or if any of the initialization steps fail. Returns `true` otherwise.

### bool isActive(string scxmlStateName)

Returns `true` if the state specified by scxmlStateName is active, `false` otherwise.

### bool isDispatchableTarget(string target)

Returns `true` if a message to target can be dispatched by this state machine.

Valid targets are:

- `#_parent` for the parent state machine if the current state machine is started by `<invoke>`
- `#_internal` for the current state machine
- `#_scxml_sessionid`, where `sessionid` is the session ID of the current state machine
- `#_servicename`, where `servicename` is the ID or name of a service started with `<invoke>` by this state machine

### void start()

Starts this state machine. The machine resets its configuration and transitions to the initial state. When a final top-level state is entered, the machine emits the finished() signal.

See also stop() and finished().

### list<string> stateNames(bool compress)

Retrieves a list of state names of all states.

When compress is `true` (the default), the states that contain child states is filtered out and only the leaf states is returned. When it is `false`, the full list of all states is returned.

The returned list does not contain the states of possible nested state machines.

Note: The order of the state names in the list is the order in which the states occurred in the SCXML document.

### void stop()

Stops this state machine. The machine will not execute any further state transitions. Its running property is set to `false`.

See also start() and finished().

### void submitEvent(event)

Submits the SCXML event event to the internal or external event queue depending on the priority of the event.

When a delay is set, the event will be queued for delivery after the timeout has passed. The state machine takes ownership of the event and deletes it after processing.

See also QScxmlEvent.

### void submitEvent(string eventName, var data)

A utility method to create and submit an external event with the specified eventName as the name and data as the payload data (optional).