QState Class
The QState class provides a general-purpose state for QStateMachine. 更多...
头文件: | #include <QState> |
qmake: | QT += core |
开始支持版本: | Qt 4.6 |
基类: | QAbstractState |
派生类: |
公有类型
enum | ChildMode { ExclusiveStates, ParallelStates } |
enum | RestorePolicy { DontRestoreProperties, RestoreProperties } |
属性
- childMode : ChildMode
- errorState : QAbstractState *
- initialState : QAbstractState *
- 1 个属性继承自 QAbstractState
- 1 个属性继承自 QObject
公有函数
QState(QState *parent = Q_NULLPTR) | |
QState(ChildMode childMode, QState *parent = Q_NULLPTR) | |
~QState() | |
void | addTransition(QAbstractTransition *transition) |
QSignalTransition * | addTransition(const QObject *sender, const char *signal, QAbstractState *target) |
QSignalTransition * | addTransition(const QObject *sender, PointerToMemberFunction signal, QAbstractState *target) |
QAbstractTransition * | addTransition(QAbstractState *target) |
void | assignProperty(QObject *object, const char *name, const QVariant &value) |
ChildMode | childMode() const |
QAbstractState * | errorState() const |
QAbstractState * | initialState() const |
void | removeTransition(QAbstractTransition *transition) |
void | setChildMode(ChildMode mode) |
void | setErrorState(QAbstractState *state) |
void | setInitialState(QAbstractState *state) |
QList<QAbstractTransition *> | transitions() const |
- 3 个公有函数继承自 QAbstractState
- 32 个公有函数继承自 QObject
信号
void | childModeChanged() |
void | errorStateChanged() |
void | finished() |
void | initialStateChanged() |
void | propertiesAssigned() |
- 3 个信号继承自 QAbstractState
- 2 个信号继承自 QObject
重新实现的受保护函数
virtual bool | event(QEvent *e) |
virtual void | onEntry(QEvent *event) |
virtual void | onExit(QEvent *event) |
- 3 个受保护的函数继承自 QAbstractState
- 9 个受保护的函数继承自 QObject
其他继承的成员
- 1 个公有槽函数继承自 QObject
- 11 个静态公有成员继承自 QObject
- 3 个受保护的函数继承自 QAbstractState
- 9 个受保护的函数继承自 QObject
详细描述
The QState class provides a general-purpose state for QStateMachine.
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).
成员类型
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. |
参见 QStateMachine::globalRestorePolicy and QState::assignProperty().
属性
childMode : ChildMode
This property holds the child mode of this state
The default value of this property is QState::ExclusiveStates.
访问函数:
ChildMode | childMode() const |
void | setChildMode(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
访问函数:
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)
访问函数:
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.
成员函数
QState::QState(QState *parent = Q_NULLPTR)
Constructs a new state with the given parent state.
QState::QState(ChildMode childMode, QState *parent = Q_NULLPTR)
Constructs a new state with the given childMode and the given parent state.
QState::~QState()
Destroys this state.
void QState::addTransition(QAbstractTransition *transition)
Adds the given transition. The transition has this state as the source. This state takes ownership of the transition.
QSignalTransition *QState::addTransition(const QObject *sender, const char *signal, QAbstractState *target)
Adds a transition associated with the given signal of the given sender object, and returns the new QSignalTransition object. The transition has this state as the source, and the given target as the target state.
QSignalTransition *QState::addTransition(const QObject *sender, PointerToMemberFunction signal, QAbstractState *target)
This is an overloaded function.
Adds a transition associated with the given signal of the given sender object, and returns the new QSignalTransition object. The transition has this state as the source, and the given target as the target state.
This function was introduced in Qt 5.5.
QAbstractTransition *QState::addTransition(QAbstractState *target)
Adds an unconditional transition from this state to the given target state, and returns then new transition object.
void QState::assignProperty(QObject *object, const char *name, const QVariant &value)
Instructs this state to set the property with the given name of the given object to the given value when the state is entered.
参见 propertiesAssigned().
ChildMode QState::childMode() const
Returns the child mode of this state.
Note: Getter function for property childMode.
参见 setChildMode().
[signal]
void QState::childModeChanged()
This signal is emitted when the childMode property is changed.
This function was introduced in Qt 5.4.
Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.
Note: Notifier signal for property childMode.
QAbstractState *QState::errorState() const
Returns this state's error state.
Note: Getter function for property errorState.
参见 setErrorState() and QStateMachine::error().
[signal]
void QState::errorStateChanged()
This signal is emitted when the errorState property is changed.
This function was introduced in Qt 5.4.
Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.
Note: Notifier signal for property errorState.
[virtual protected]
bool QState::event(QEvent *e)
Reimplemented from QObject::event().
[signal]
void QState::finished()
This signal is emitted when a final child state of this state is entered.
Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.
参见 QFinalState.
QAbstractState *QState::initialState() const
Returns this state's initial state, or 0 if the state has no initial state.
Note: Getter function for property initialState.
参见 setInitialState().
[signal]
void QState::initialStateChanged()
This signal is emitted when the initialState property is changed.
This function was introduced in Qt 5.4.
Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.
Note: Notifier signal for property initialState.
[virtual protected]
void QState::onEntry(QEvent *event)
Reimplemented from QAbstractState::onEntry().
[virtual protected]
void QState::onExit(QEvent *event)
Reimplemented from QAbstractState::onExit().
[signal]
void QState::propertiesAssigned()
This signal is emitted when all properties have been assigned their final value. If the state assigns a value to one or more properties for which an animation exists (either set on the transition or as a default animation on the state machine), then the signal will not be emitted until all such animations have finished playing.
If there are no relevant animations, or no property assignments defined for the state, then the signal will be emitted immediately before the state is entered.
Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.
参见 QState::assignProperty() and QAbstractTransition::addAnimation().
void QState::removeTransition(QAbstractTransition *transition)
Removes the given transition from this state. The state releases ownership of the transition.
参见 addTransition().
void QState::setChildMode(ChildMode mode)
Sets the child mode of this state.
Note: Setter function for property childMode.
参见 childMode().
void QState::setErrorState(QAbstractState *state)
Sets this state's error state to be the given state. If the error state is not set, or if it is set to 0, the state will inherit its parent's error state recursively. If no error state is set for the state itself or any of its ancestors, an error will cause the machine to stop executing and an error will be printed to the console.
Note: Setter function for property errorState.
参见 errorState().
void QState::setInitialState(QAbstractState *state)
Sets this state's initial state to be the given state. state has to be a child of this state.
Note: Setter function for property initialState.
参见 initialState().
QList<QAbstractTransition *> QState::transitions() const
Returns this state's outgoing transitions (i.e. transitions where this state is the source state), or an empty list if this state has no outgoing transitions.
This function was introduced in Qt 4.7.
参见 addTransition().