PySide6.QtScxml.QScxmlStateMachine - Qt for Python
PySide6.QtScxml.QScxmlStateMachine - Qt for Python
P y S i d e 6 .Q t S c x m l .Q S c x m l S t a t e M a c h i n e
class QScxmlStateMachine
The QScxmlStateMachine class provides an interface to the state machines created from SCXML
files. More…
Sy n o p s i s
P ro p e r t i e s
• dataModel - Data model to be used for this state machine
• initialValues - Initial values to be used for setting up the data model
• initialized - Whether the state machine has been initialized
• invoked - Whether the state machine was invoked from an outer state machine
• invokedServices - A list of SCXML services that were invoked from the main state machine
(possibly recursively)
• loader - That is currently used to resolve and load URIs for the state machine
• name - Of the state machine as set by the name attribute of the <scxml> tag
• parseErrors - List of parse errors that occurred while creating a state machine from an SCXML
file
• running - The running state of this state machine
• sessionId - Session ID of the current state machine
• tableData - Table data that is used when generating C++ from an SCXML file
Method s
• def __init__()
• def activeStateNames()
• def cancelDelayedEvent()
• def connectToEvent()
• def connectToState()
• def dataModel()
• def initialValues()
• def invokedServices()
1 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
• def invokedServices()
• def isActive()
• def isDispatchableTarget()
• def isInitialized()
• def isInvoked()
• def isRunning()
• def loader()
• def name()
• def parseErrors()
• def sessionId()
• def setDataModel()
• def setInitialValues()
• def setLoader()
• def setRunning()
• def setTableData()
• def stateNames()
• def submitEvent()
• def tableData()
Sl ots
• def init()
• def start()
• def stop()
Signals
• def dataModelChanged()
• def finished()
• def initialValuesChanged()
• def initializedChanged()
• def invokedServicesChanged()
• def loaderChanged()
• def log()
• def reachedStableState()
• def runningChanged()
• def tableDataChanged()
2 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
• def tableDataChanged()
St a t i c f u n c t i o n s
• def fromData()
• def fromFile()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always
welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by
creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description
QScxmlStateMachine is an implementation of the State Chart XML (SCXML) .
All states that are defined in the SCXML file are accessible as properties of QScxmlStateMachine .
These properties are boolean values and indicate whether the state is active or inactive.
Note
The QScxmlStateMachine needs a QEventLoop to work correctly. The event loop is used to implement the delay
attribute for events and to schedule the processing of a state machine when events are received from nested (or
parent) state machines.
Note
Properties can be used directly when from __feature__ import true_property is used or via accessor functions
otherwise.
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
3 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
Acce s s f u n c t i o n s :
• dataModel()
• setDataModel()
• Signal dataModelChanged()
See also
init() QScxmlDataModel
Acce s s f u n c t i o n s :
• initialValues()
• setInitialValues()
• Signal initialValuesChanged()
See also
init() QScxmlDataModel
Acce s s f u n c t i o n s :
• isInitialized()
• Signal initializedChanged()
true when the state machine was started as a service with the <invoke> element, false
4 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
otherwise.
Acce s s f u n c t i o n s :
• isInvoked()
Acce s s f u n c t i o n s :
• invokedServices()
• Signal invokedServicesChanged()
Acce s s f u n c t i o n s :
• loader()
• setLoader()
• Signal loaderChanged()
Acce s s f u n c t i o n s :
• name()
Acce s s f u n c t i o n s :
• parseErrors()
5 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
See also
start()
Acce s s f u n c t i o n s :
• isRunning()
• setRunning()
• Signal runningChanged()
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.
See also
invokeId()
Acce s s f u n c t i o n s :
• sessionId()
The class implementing the state machine will use this property to assign the generated table
data. The state machine does not assume ownership of the table data.
Acce s s f u n c t i o n s :
• tableData()
• setTableData()
• Signal tableDataChanged()
__init__(metaObject[, parent=None])
6 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
PARAMETERS:
• metaObject – QMetaObject
• parent – QObject
activeStateNames([compress=true])
PARAMETERS:
compress – bool
RETURN TYPE:
list of strings
When a state is active, all its parent states are active by definition. When compress is true (the
default), the parent states will be filtered out and only the leaf states will be returned. When it is
false , the full list of active states will be returned.
cancelDelayedEvent(sendId)
PARAMETERS:
sendId – str
RETURN TYPE:
Connection
Creates a connection of the specified type from the event specified by scxmlEventSpec to the
method in the receiver object. The receiver’s method may take a QScxmlEvent as a parameter. For
example:
7 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
In contrast to event specifications in SCXML documents, spaces are not allowed in the
scxmlEventSpec here. In order to connect to multiple events with different prefixes,
connectToEvent() has to be called multiple times.
RETURN TYPE:
Connection
Creates a connection of the given type from the state identified by scxmlStateName to the method
in the receiver object. The receiver’s method may take a boolean argument that indicates
whether the state connected became active or inactive. For example:
dataModel()
RETURN TYPE:
QScxmlDataModel
See also
setDataModel()
8 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
dataModelChanged(model)
PARAMETERS:
model – QScxmlDataModel
finished()
This signal is emitted when the state machine reaches a top-level final state.
See also
running
RETURN TYPE:
QScxmlStateMachine
This method will always return a state machine. If errors occur while reading the SCXML file,
fileName , the state machine cannot be started. The errors can be retrieved by calling the
parseErrors() method.
See also
parseErrors()
static fromFile(fileName)
PARAMETERS:
fileName – str
RETURN TYPE:
QScxmlStateMachine
9 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
This method will always return a state machine. If errors occur while reading the SCXML file, the
state machine cannot be started. The errors can be retrieved by calling the parseErrors()
method.
See also
parseErrors()
init()
RETURN TYPE:
bool
State machine initialization consists of calling setup() , 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.
initialValues()
RETURN TYPE:
Dictionary with keys of type .QString and values of type QVariant.
See also
setInitialValues()
initialValuesChanged(initialValues)
PARAMETERS:
initialValues – Dictionary with keys of type .QString and values of type QVariant.
initializedChanged(initialized)
PARAMETERS:
10 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
initialized – bool
invokedServices()
RETURN TYPE:
.list of QScxmlInvokableService
invokedServicesChanged(invokedServices)
PARAMETERS:
invokedServices – .list of QScxmlInvokableService
isActive(scxmlStateName)
PARAMETERS:
scxmlStateName – str
RETURN TYPE:
bool
isActive(stateIndex)
PARAMETERS:
stateIndex – int
RETURN TYPE:
bool
This method is part of the interface to the compiled representation of SCXML state machines. It
should only be used internally and by state machines compiled from SCXML documents.
isDispatchableTarget(target)
PARAMETERS:
target – str
RETURN TYPE:
bool
11 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
• #_parent for the parent state machine if the current state machine is started by
<invoke>
isInitialized()
RETURN TYPE:
bool
isInvoked()
RETURN TYPE:
bool
isRunning()
RETURN TYPE:
bool
See also
setRunning() runningChanged()
loader()
RETURN TYPE:
12 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
Loader
See also
setLoader()
loaderChanged(loader)
PARAMETERS:
loader – Loader
log(label, msg)
PARAMETERS:
• label – str
• msg – str
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.
name()
RETURN TYPE:
str
parseErrors()
RETURN TYPE:
.list of QScxmlError
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.
runningChanged(running)
PARAMETERS:
running – bool
13 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
running – bool
This signal is emitted when the running property is changed with running as argument.
sessionId()
RETURN TYPE:
str
setDataModel(model)
PARAMETERS:
model – QScxmlDataModel
Sets the data model for this state machine to model . There is a 1:1 relation between state
machines and models. After setting the model once you cannot change it anymore. Any further
attempts to set the model using this method will be ignored.
See also
dataModel()
setInitialValues(initialValues)
PARAMETERS:
initialValues – Dictionary with keys of type .QString and values of type QVariant.
See also
initialValues()
setLoader(loader)
PARAMETERS:
loader – Loader
See also
14 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
loader()
setRunning(running)
PARAMETERS:
running – bool
See also
setTableData(tableData)
PARAMETERS:
tableData – QScxmlTableData
See also
tableData()
start()
Starts this state machine. When a final top-level state is entered, the machine will emit the
finished() signal.
Note
A state machine will not run without a running event loop, such as the main application event loop started with
QCoreApplication::exec() or QApplication::exec().
Note
Calling start() after stop() will not result in a full reset of its configuration yet, hence it is strongly advised not to do
it.
Note
15 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
See also
stateNames([compress=true])
PARAMETERS:
compress – bool
RETURN TYPE:
list of strings
When compress is true (the default), the states that contain child states will be filtered out and
only the leaf states will be returned. When it is false , the full list of all states will be 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.
stop()
Stops this state machine. The machine will not execute any further state transitions. Its running
property is set to false .
See also
submitEvent(event)
PARAMETERS:
event – QScxmlEvent
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 event and deletes it after processing.
16 of 17 13-Dec-24, 11:09
PySide6.QtScxml.QScxmlStateMachine - Qt for Python https://doc.qt.io/qtforpython-6/PySide6/QtScxml/QScxmlStateMachine...
submitEvent(eventName)
PARAMETERS:
eventName – str
A utility method to create and submit an external event with the specified eventName as the
name.
submitEvent(eventName, data)
PARAMETERS:
• eventName – str
• data – object
A utility method to create and submit an external event with the specified eventName as the name
and data as the payload data.
tableData()
RETURN TYPE:
QScxmlTableData
See also
setTableData()
tableDataChanged(tableData)
PARAMETERS:
tableData – QScxmlTableData
Copyright © 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.
The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 (https://
www.gnu.org/licenses/fdl.html) as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt
Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.
Made with Sphinx and @pradyunsg's Furo
17 of 17 13-Dec-24, 11:09