QState Class
The QState class provides a general-purpose state for QStateMachine. More...
| Header: | #include <QState> |
| qmake: | QT += core |
| Since: | Qt 4.6 |
| Inherits: | QAbstractState |
| Inherited By: |
This class was introduced in Qt 4.6.
Public Types
| enum | ChildMode { ExclusiveStates, ParallelStates } |
| enum | RestorePolicy { DontRestoreProperties, RestoreProperties } |
Properties
- childMode : ChildMode
- errorState : QAbstractState*
- initialState : QAbstractState*
Public Functions
| QState::ChildMode | childMode() const |
| QAbstractState * | errorState() const |
| QAbstractState * | initialState() const |
| void | setChildMode(QState::ChildMode mode) |
| void | setErrorState(QAbstractState *state) |
| void | setInitialState(QAbstractState *state) |
Signals
| void | childModeChanged() |
| void | errorStateChanged() |
| void | initialStateChanged() |
Detailed Description
QState objects can have child states, and can have transitions to other states. QState is part of The State Machine Framework.
The addTransition() function adds a transition. The removeTransition() function removes a transition. The transitions() function returns the state's outgoing transitions.
The assignProperty() function is used for defining property assignments that should be performed when a state is entered.
Top-level states must be passed a QStateMachine object as their parent state, or added to a state machine using QStateMachine::addState().
States with Child States
The childMode property determines how child states are treated. For non-parallel state groups, the setInitialState() function must be called to set the initial state. The child states are mutually exclusive states, and the state machine needs to know which child state to enter when the parent state is the target of a transition.
The state emits the QState::finished() signal when a final child state (QFinalState) is entered.
The setErrorState() sets the state's error state. The error state is the state that the state machine will transition to if an error is detected when attempting to enter the state (e.g. because no initial state has been set).
Member Type Documentation
enum QState::ChildMode
This enum specifies how a state's child states are treated.
| Constant | Value | Description |
|---|---|---|
QState::ExclusiveStates | 0 | The child states are mutually exclusive and an initial state must be set by calling QState::setInitialState(). |
QState::ParallelStates | 1 | The child states are parallel. When the parent state is entered, all its child states are entered in parallel. |
enum QState::RestorePolicy
This enum specifies the restore policy type. The restore policy takes effect when the machine enters a state which sets one or more properties. If the restore policy is set to RestoreProperties, the state machine will save the original value of the property before the new value is set.
Later, when the machine either enters a state which does not set a value for the given property, the property will automatically be restored to its initial value.
Only one initial value will be saved for any given property. If a value for a property has already been saved by the state machine, it will not be overwritten until the property has been successfully restored.
| Constant | Value | Description |
|---|---|---|
QState::DontRestoreProperties | 0 | The state machine should not save the initial values of properties and restore them later. |
QState::RestoreProperties | 1 | The state machine should save the initial values of properties and restore them later. |
See also QStateMachine::globalRestorePolicy and QState::assignProperty().
Property Documentation
childMode : ChildMode
This property holds the child mode of this state
The default value of this property is QState::ExclusiveStates.
Access functions:
| QState::ChildMode | childMode() const |
| void | setChildMode(QState::ChildMode mode) |
Notifier signal:
| void | childModeChanged() | [see note below] |
Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.
errorState : QAbstractState*
This property holds the error state of this state
Access functions:
| QAbstractState * | errorState() const |
| void | setErrorState(QAbstractState *state) |
Notifier signal:
| void | errorStateChanged() | [see note below] |
Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.
initialState : QAbstractState*
This property holds the initial state of this state (one of its child states)
Access functions:
| QAbstractState * | initialState() const |
| void | setInitialState(QAbstractState *state) |
Notifier signal:
| void | initialStateChanged() | [see note below] |
Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.