Skip to content

PythonQt.Qt.QStateMachine

QStateMachine

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

QStateMachine is based on the concepts and notation of Statecharts. QStateMachine is part of The State Machine Framework.

A state machine manages a set of states (classes that inherit from QAbstractState) and transitions (descendants of QAbstractTransition) between those states; these states and transitions define a state graph. Once a state graph has been built, the state machine can execute it. QStateMachine's execution algorithm is based on the State Chart XML (SCXML) algorithm. The framework's overview gives several state graphs and the code to build them.

Use the addState() function to add a top-level state to the state machine. States are removed with the removeState() function. Removing states while the machine is running is discouraged.

Before the machine can be started, the initial state must be set. The initial state is the state that the machine enters when started. You can then start() the state machine. The started() signal is emitted when the initial state is entered.

The machine is event driven and keeps its own event loop. Events are posted to the machine through postEvent(). Note that this means that it executes asynchronously, and that it will not progress without a running event loop. You will normally not have to post events to the machine directly as Qt's transitions, e.g., QEventTransition and its subclasses, handle this. But for custom transitions triggered by events, postEvent() is useful.

The state machine processes events and takes transitions until a top-level final state is entered; the state machine then emits the finished() signal. You can also stop() the state machine explicitly. The stopped() signal is emitted in this case.

The following snippet shows a state machine that will finish when a button is clicked:

QPushButton button;

QStateMachine machine;
QState *s1 = new QState();
s1->assignProperty(&button, "text", "Click me");

QFinalState *s2 = new QFinalState();
s1->addTransition(&button, &QPushButton::clicked, s2);

machine.addState(s1);
machine.addState(s2);
machine.setInitialState(s1);
machine.start();

This code example uses QState, which inherits QAbstractState. The QState class provides a state that you can use to set properties and invoke methods on QObjects when the state is entered or exited. It also contains convenience functions for adding transitions, e.g., QSignalTransitions as in this example. See the QState class description for further details.

If an error is encountered, the machine will look for an error state, and if one is available, it will enter this state. The types of errors possible are described by the Error enum. After the error state is entered, the type of the error can be retrieved with error(). The execution of the state graph will not stop when the error state is entered. If no error state applies to the erroneous state, the machine will stop executing and an error message will be printed to the console.

Note: Important: setting the ChildMode of a state machine to parallel (ParallelStates) results in an invalid state machine. It can only be set to (or kept as) ExclusiveStates.

Source: https://doc.qt.io/archives/qt-5.15/qstatemachine.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
ChildMode attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
DontRestoreProperties attribute Any (shared captured text)
Error attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
EventPriority attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
ExclusiveStates attribute Any (shared captured text)
HighPriority attribute Any (shared captured text)
NoCommonAncestorForTransitionError attribute Any (shared captured text)
NoDefaultStateInHistoryStateError attribute Any (shared captured text)
NoError attribute Any (shared captured text)
NoInitialStateError attribute Any (shared captured text)
NormalPriority attribute Any (shared captured text)
ParallelStates attribute Any (shared captured text)
RestorePolicy attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
RestoreProperties attribute Any (shared captured text)
SignalEvent attribute type (shared captured text)
WrappedEvent attribute type (shared captured text)
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
active attribute Any (shared captured text)
activeChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QStateMachine.activeChanged; argument details are not documented.
addDefaultAnimation function (self, animation: Any) -> None Adds a default animation to be considered for any transition. (shared captured text)
addState function (self, state: Any) -> None Adds the given state to this state machine. (shared captured text)
addTransition function (self, sender: Any, signal: Any, target: Any) -> Any X.addTransition(sender, signal, target) -> PythonQt.QtCore.QAbstractTransition (shared captured text)
animated attribute Any This property holds whether animations are enabled (shared captured text)
assignProperty function (self, object: Any, name: Any, value: Any) -> Any X.assignProperty(object, name, value) (shared captured text)
beginMicrostep function (self, event: Any) -> None (shared captured text)
beginSelectTransitions function (self, event: Any) -> None (shared captured text)
blockSignals function (self, b: Any) -> bool X.blockSignals(b) -> bool (shared captured text)
cancelDelayedEvent function (self, id: int) -> bool X.cancelDelayedEvent(id) -> bool (shared captured text)
childEvent function (self, event: Any) -> Any (shared captured text)
childMode attribute Any (shared captured text)
childModeChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QStateMachine.childModeChanged; argument details are not documented.
children function (self) -> tuple X.children() -> tuple (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
clearError function (self) -> None Clears the error string and error code of the state machine. (shared captured text)
configuration function (self) -> Any Returns the maximal consistent set of states (including parallel and final states) that this state machine is currently in. (shared captured text)
connect function (self, signal: Any, receiver: Any, slot: Any, type: Any) -> bool X.connect(signal, receiver, slot, type) -> bool (shared captured text)
customEvent function (self, event: Any) -> Any (shared captured text)
defaultAnimations function (self) -> tuple X.defaultAnimations() -> tuple (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
deleteLater function (self) -> Any (shared captured text)
destroyed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QStateMachine.destroyed; argument details are not documented.
disconnect function (self, signal: Any, receiver: Any, slot: Any) -> bool X.disconnect(signal, receiver, slot) -> bool (shared captured text)
dumpObjectInfo function (self) -> Any (shared captured text)
dumpObjectTree function (self) -> Any (shared captured text)
dynamicPropertyNames function (self) -> Any (shared captured text)
endMicrostep function (self, event: Any) -> None (shared captured text)
endSelectTransitions function (self, event: Any) -> None (shared captured text)
entered function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QStateMachine.entered; argument details are not documented.
error function (self) -> Any Returns the error code of the last error that occurred in the state machine. (shared captured text)
errorState attribute QAbstractState (shared captured text)
errorStateChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QStateMachine.errorStateChanged; argument details are not documented.
errorString attribute str This property holds the error string of this state machine (shared captured text)
event function (self, e: Any) -> bool X.event(e) -> bool (shared captured text)
eventFilter function (self, watched: Any, event: Any) -> bool X.eventFilter(watched, event) -> bool (shared captured text)
exited function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QStateMachine.exited; argument details are not documented.
findChild function (self, type: Any, name: Any) -> Any X.findChild(type, name) -> PythonQt.private.QObject (shared captured text)
findChildren function (self, type: Any, name: Any) -> tuple X.findChildren(type, name) -> tuple (shared captured text)
finished function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QStateMachine.finished; argument details are not documented.
globalRestorePolicy attribute Any This property holds the restore policy for states of this state machine. (shared captured text)
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
initialState attribute QAbstractState (shared captured text)
initialStateChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QStateMachine.initialStateChanged; argument details are not documented.
installEventFilter function (self, filterObj: Any) -> Any (shared captured text)
isAnimated function (self) -> bool X.isAnimated() -> bool (shared captured text)
isRunning function (self) -> bool X.isRunning() -> bool (shared captured text)
isSignalConnected function (self, signal: Any) -> bool X.isSignalConnected(signal) -> bool (shared captured text)
isWidgetType function (self) -> bool X.isWidgetType() -> bool (shared captured text)
isWindowType function (self) -> bool X.isWindowType() -> bool (shared captured text)
killTimer function (self, id: Any) -> Any (shared captured text)
machine function (self) -> Any X.machine() -> PythonQt.QtCore.QStateMachine (shared captured text)
metaObject function (self) -> Any X.metaObject() -> PythonQt.QtCore.QMetaObject (shared captured text)
moveToThread function (self, thread: Any) -> Any (shared captured text)
objectName attribute Any (shared captured text)
objectNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QStateMachine.objectNameChanged; argument details are not documented.
onEntry function (self, event: Any) -> None Reimplements: [QState::onEntry](https://doc.qt.io/archives/qt-5.15/qstate.html#onEntry)(QEvent *event). (shared captured text)
onExit function (self, event: Any) -> None Reimplements: [QState::onExit](https://doc.qt.io/archives/qt-5.15/qstate.html#onExit)(QEvent *event). (shared captured text)
parent function (self) -> Any X.parent() -> PythonQt.private.QObject (shared captured text)
parentState function (self) -> Any X.parentState() -> PythonQt.QtCore.QState (shared captured text)
postDelayedEvent function (self, event: Any, delay: int) -> int X.postDelayedEvent(event, delay) -> int (shared captured text)
postEvent function (self, event: Any, priority: Any) -> None X.postEvent(event, priority) (shared captured text)
propertiesAssigned function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QStateMachine.propertiesAssigned; argument details are not documented.
property function (self, name: Any) -> Any X.property(name) -> object (shared captured text)
removeDefaultAnimation function (self, animation: Any) -> None Removes animation from the list of default animations. (shared captured text)
removeEventFilter function (self, obj: Any) -> Any (shared captured text)
removeState function (self, state: Any) -> None Removes the given state from this state machine. (shared captured text)
removeTransition function (self, transition: Any) -> Any (shared captured text)
running attribute Any This property holds the running state of this state machine (shared captured text)
runningChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QStateMachine.runningChanged; argument details are not documented.
sender function (self) -> Any X.sender() -> PythonQt.private.QObject (shared captured text)
senderSignalIndex function (self) -> int X.senderSignalIndex() -> int (shared captured text)
setAnimated function (self, enabled: bool) -> None Sets whether animations are enabled for this state machine. (shared captured text)
setChildMode function (self, mode: Any) -> Any (shared captured text)
setErrorState function (self, state: Any) -> Any (shared captured text)
setGlobalRestorePolicy function (self, restorePolicy: Any) -> None Sets the restore policy of the state machine to restorePolicy. (shared captured text)
setInitialState function (self, state: Any) -> Any (shared captured text)
setObjectName function (self, name: Any) -> Any (shared captured text)
setParent function (self, parent: Any) -> Any (shared captured text)
setProperty function (self, name: Any, value: Any) -> bool X.setProperty(name, value) -> bool (shared captured text)
setRunning function (self, running: bool) -> None (shared captured text)
signalsBlocked function (self) -> bool X.signalsBlocked() -> bool (shared captured text)
start function (self) -> None Starts this state machine. (shared captured text)
startTimer function (self, interval: Any, timerType: Any) -> int X.startTimer(interval, timerType) -> int (shared captured text)
started function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QStateMachine.started; argument details are not documented.
stop function (self) -> None Stops this state machine. (shared captured text)
stopped function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QStateMachine.stopped; argument details are not documented.
thread function (self) -> Any (shared captured text)
timerEvent function (self, event: Any) -> Any (shared captured text)
tr function (self, text: Any, ambig: Any, n: Any) -> str X.tr(text, ambig, n) -> str (shared captured text)
transitions function (self) -> tuple X.transitions() -> tuple (shared captured text)