PythonQt.QtCore.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. |
EventPriority |
attribute | type |
Convert a number or string to an integer, or return 0 if no arguments are given. |
ExclusiveStates |
attribute | Any |
(shared captured text) |
HighPriority |
attribute | Any |
|
NoCommonAncestorForTransitionError |
attribute | Any |
|
NoDefaultStateInHistoryStateError |
attribute | Any |
|
NoError |
attribute | Any |
(shared captured text) |
NoInitialStateError |
attribute | Any |
|
NormalPriority |
attribute | Any |
|
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 |
|
WrappedEvent |
attribute | type |
|
__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.QtCore.QStateMachine.activeChanged; argument details are not documented. |
addDefaultAnimation |
function | (self, animation: Any) -> None |
Adds a default animation to be considered for any transition. |
addState |
function | (self, state: Any) -> None |
Adds the given state to this state machine. |
addTransition |
function | (self, sender: Any, signal: Any, target: Any) -> Any |
X.addTransition(sender, signal, target) -> PythonQt.QtCore.QAbstractTransition |
animated |
attribute | Any |
This property holds whether animations are enabled |
assignProperty |
function | (self, object: Any, name: Any, value: Any) -> Any |
X.assignProperty(object, name, value) |
beginMicrostep |
function | (self, event: Any) -> None |
|
beginSelectTransitions |
function | (self, event: Any) -> None |
|
blockSignals |
function | (self, b: Any) -> bool |
X.blockSignals(b) -> bool (shared captured text) |
cancelDelayedEvent |
function | (self, id: int) -> bool |
X.cancelDelayedEvent(id) -> bool |
childEvent |
function | (self, event: Any) -> Any |
(shared captured text) |
childMode |
attribute | Any |
|
childModeChanged |
function | (self, *args: Any, **kwargs: Any) -> Any |
Native PythonQt.QtCore.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. |
configuration |
function | (self) -> Any |
Returns the maximal consistent set of states (including parallel and final states) that this state machine is currently in. |
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 |
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.QtCore.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 |
|
endSelectTransitions |
function | (self, event: Any) -> None |
|
entered |
function | (self, *args: Any, **kwargs: Any) -> Any |
Native PythonQt.QtCore.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. |
errorState |
attribute | QAbstractState |
|
errorStateChanged |
function | (self, *args: Any, **kwargs: Any) -> Any |
Native PythonQt.QtCore.QStateMachine.errorStateChanged; argument details are not documented. |
errorString |
attribute | str |
This property holds the error string of this state machine |
event |
function | (self, e: Any) -> bool |
X.event(e) -> bool |
eventFilter |
function | (self, watched: Any, event: Any) -> bool |
X.eventFilter(watched, event) -> bool |
exited |
function | (self, *args: Any, **kwargs: Any) -> Any |
Native PythonQt.QtCore.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.QtCore.QStateMachine.finished; argument details are not documented. |
globalRestorePolicy |
attribute | Any |
This property holds the restore policy for states of this state machine. |
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 |
|
initialStateChanged |
function | (self, *args: Any, **kwargs: Any) -> Any |
Native PythonQt.QtCore.QStateMachine.initialStateChanged; argument details are not documented. |
installEventFilter |
function | (self, filterObj: Any) -> Any |
(shared captured text) |
isAnimated |
function | (self) -> bool |
X.isAnimated() -> bool |
isRunning |
function | (self) -> bool |
X.isRunning() -> bool |
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.QtCore.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). |
onExit |
function | (self, event: Any) -> None |
Reimplements: [QState::onExit](https://doc.qt.io/archives/qt-5.15/qstate.html#onExit)(QEvent *event). |
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 |
postEvent |
function | (self, event: Any, priority: Any) -> None |
X.postEvent(event, priority) |
propertiesAssigned |
function | (self, *args: Any, **kwargs: Any) -> Any |
Native PythonQt.QtCore.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. |
removeEventFilter |
function | (self, obj: Any) -> Any |
(shared captured text) |
removeState |
function | (self, state: Any) -> None |
Removes the given state from this state machine. |
removeTransition |
function | (self, transition: Any) -> Any |
|
running |
attribute | Any |
This property holds the running state of this state machine |
runningChanged |
function | (self, *args: Any, **kwargs: Any) -> Any |
Native PythonQt.QtCore.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. |
setChildMode |
function | (self, mode: Any) -> Any |
|
setErrorState |
function | (self, state: Any) -> Any |
|
setGlobalRestorePolicy |
function | (self, restorePolicy: Any) -> None |
Sets the restore policy of the state machine to restorePolicy. |
setInitialState |
function | (self, state: Any) -> Any |
|
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 |
|
signalsBlocked |
function | (self) -> bool |
X.signalsBlocked() -> bool (shared captured text) |
start |
function | (self) -> None |
Starts this state machine. |
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.QtCore.QStateMachine.started; argument details are not documented. |
stop |
function | (self) -> None |
Stops this state machine. |
stopped |
function | (self, *args: Any, **kwargs: Any) -> Any |
Native PythonQt.QtCore.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 |