QState 类

The QState class provides a general-purpose state for QStateMachine . 更多...

头: #include <QState>
CMake: find_package(Qt6 COMPONENTS StateMachine REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::StateMachine)
qmake: QT += statemachine
继承: QAbstractState
继承者: QStateMachine

公共类型

enum ChildMode { ExclusiveStates, ParallelStates }
enum RestorePolicy { DontRestoreProperties, RestoreProperties }

特性

公共函数

  QState (QState::ChildMode childMode , QState * parent = nullptr)
  QState (QState * parent = nullptr)
virtual ~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 )
QState::ChildMode childMode () const
QAbstractState * errorState () const
QAbstractState * initialState () const
void removeTransition (QAbstractTransition * transition )
void setChildMode (QState::ChildMode mode )
void setErrorState (QAbstractState * state )
void setInitialState (QAbstractState * state )
QList<QAbstractTransition *> transitions () const

信号

void childModeChanged ()
void errorStateChanged ()
void finished ()
void initialStateChanged ()
void propertiesAssigned ()

重实现保护函数

virtual bool event (QEvent * e ) override
virtual void onEntry (QEvent * event ) override
virtual void onExit (QEvent * event ) override

详细描述

QState objects can have child states, and can have transitions to other states. QState is part of Qt State Machine Framework .

addTransition () function adds a transition. The removeTransition () function removes a transition. The transitions () function returns the state's outgoing transitions.

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 ().

具有子级状态的状态

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.

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.

常量 描述
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.

常量 描述
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 ().

特性文档编制

[bindable] childMode : ChildMode

注意: 此特性支持 QProperty 绑定。

This property holds the child mode of this state

此特性的默认值为 QState::ExclusiveStates .

[bindable] errorState : QAbstractState *

注意: 此特性支持 QProperty 绑定。

此特性保持此状态的错误状态

[bindable] initialState : QAbstractState *

注意: 此特性支持 QProperty 绑定。

This property holds the initial state of this state (one of its child states)

成员函数文档编制

QState:: QState ( QState::ChildMode childMode , QState * parent = nullptr)

构造新的状态采用给定 childMode 和给定 parent 状态。

QState:: QState ( QState * parent = nullptr)

构造新的状态采用给定 parent 状态。

[private signal, since 5.4] void QState:: childModeChanged ()

此信号被发射当 childMode 特性改变。

注意: 这是私有信号。它可以用于信号连接,但不能由用户发射。

注意: 通知程序信号对于特性 childMode .

该函数在 Qt 5.4 引入。

另请参阅 QState::childMode .

[private signal, since 5.4] void QState:: errorStateChanged ()

此信号被发射当 errorState 特性改变。

注意: 这是私有信号。它可以用于信号连接,但不能由用户发射。

注意: 通知程序信号对于特性 errorState .

该函数在 Qt 5.4 引入。

另请参阅 QState::errorState .

[private signal] void QState:: finished ()

This signal is emitted when a final child state of this state is entered.

注意: 这是私有信号。它可以用于信号连接,但不能由用户发射。

另请参阅 QFinalState .

[private signal, since 5.4] void QState:: initialStateChanged ()

此信号被发射当 initialState 特性改变。

注意: 这是私有信号。它可以用于信号连接,但不能由用户发射。

注意: 通知程序信号对于特性 initialState .

该函数在 Qt 5.4 引入。

另请参阅 QState::initialState .

[private 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.

另请参阅 QState::assignProperty () 和 QAbstractTransition::addAnimation ()

注意: 这是私有信号。它可以用于信号连接,但不能由用户发射。

[虚拟] QState:: ~QState ()

销毁此状态。

void QState:: addTransition ( QAbstractTransition * transition )

添加给定 transition 。过渡拥有此状态因为源。此状态拥有过渡的所有权。

QSignalTransition *QState:: addTransition (const QObject * sender , const char * signal , QAbstractState * target )

Adds a transition associated with the given signal 为给定 sender 对象,并返回新的 QSignalTransition object. The transition has this state as the source, and the given target as the target state.

[since 5.5] template <typename PointerToMemberFunction> QSignalTransition *QState:: addTransition (const QObject * sender , PointerToMemberFunction signal , QAbstractState * target )

这是重载函数。

Adds a transition associated with the given signal 为给定 sender 对象,并返回新的 QSignalTransition object. The transition has this state as the source, and the given target as the target state.

该函数在 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 为给定 object 到给定 value when the state is entered.

另请参阅 propertiesAssigned ().

QState::ChildMode QState:: childMode () const

Returns the child mode of this state.

注意: Getter function for property childMode.

另请参阅 setChildMode ().

QAbstractState *QState:: errorState () const

Returns this state's error state.

注意: Getter function for property errorState.

另请参阅 setErrorState () 和 QStateMachine::error ().

[override virtual protected] bool QState:: event ( QEvent * e )

重实现: QAbstractState::event (QEvent *e).

QAbstractState *QState:: initialState () const

Returns this state's initial state, or nullptr if the state has no initial state.

注意: Getter function for property initialState.

另请参阅 setInitialState ().

[override virtual protected] void QState:: onEntry ( QEvent * event )

重实现: QAbstractState::onEntry (QEvent *event).

[override virtual protected] void QState:: onExit ( QEvent * event )

重实现: QAbstractState::onExit (QEvent *event).

void QState:: removeTransition ( QAbstractTransition * transition )

移除给定 transition from this state. The state releases ownership of the transition.

另请参阅 addTransition ().

void QState:: setChildMode ( QState::ChildMode mode )

设置子级 mode of this state.

注意: setter 函数对于特性 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 nullptr , 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.

注意: setter 函数对于特性 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.

注意: setter 函数对于特性 initialState .

另请参阅 initialState ().

QList < QAbstractTransition *> QState:: 过渡 () 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.

另请参阅 addTransition ().