QScxmlStateMachine Class

The QScxmlStateMachine class provides an interface to the state machines created from SCXML files. 更多...

头: #include <QScxmlStateMachine>
CMake: find_package(Qt6 REQUIRED COMPONENTS Scxml)
target_link_libraries(mytarget PRIVATE Qt6::Scxml)
qmake: QT += scxml
实例化: ScxmlStateMachine
继承: QObject

特性

公共函数

QStringList activeStateNames (bool compress = true) const
QBindable<QScxmlDataModel *> bindableDataModel ()
QBindable<QVariantMap> bindableInitialValues ()
QBindable<bool> bindableInitialized () const
QBindable<QList<QScxmlInvokableService *>> bindableInvokedServices ()
QBindable<QScxmlCompiler::Loader *> bindableLoader ()
QBindable<QScxmlTableData *> bindableTableData ()
void cancelDelayedEvent (const QString & sendId )
QMetaObject::Connection connectToEvent (const QString & scxmlEventSpec , const QObject * receiver , const char * method , Qt::ConnectionType type = Qt::AutoConnection)
QMetaObject::Connection connectToEvent (const QString & scxmlEventSpec , const typename QtPrivate::FunctionPointer<PointerToMemberFunction>::Object * receiver , PointerToMemberFunction method , Qt::ConnectionType type = Qt::AutoConnection)
typename std::enable_if<!QtPrivate::FunctionPointer<Functor>::IsPointerToMemberFunction && !std::is_same<const char *, Functor>::value, QMetaObject::Connection>::type connectToEvent (const QString & scxmlEventSpec , Functor functor , Qt::ConnectionType type = Qt::AutoConnection)
typename std::enable_if<!QtPrivate::FunctionPointer<Functor>::IsPointerToMemberFunction && !std::is_same<const char *, Functor>::value, QMetaObject::Connection>::type connectToEvent (const QString & scxmlEventSpec , const QObject * context , Functor functor , Qt::ConnectionType type = Qt::AutoConnection)
QMetaObject::Connection connectToState (const QString & scxmlStateName , const QObject * receiver , const char * method , Qt::ConnectionType type = Qt::AutoConnection)
QMetaObject::Connection connectToState (const QString & scxmlStateName , const typename QtPrivate::FunctionPointer<PointerToMemberFunction>::Object * receiver , PointerToMemberFunction method , Qt::ConnectionType type = Qt::AutoConnection)
typename std::enable_if<!QtPrivate::FunctionPointer<Functor>::IsPointerToMemberFunction && !std::is_same<const char *, Functor>::value, QMetaObject::Connection>::type connectToState (const QString & scxmlStateName , Functor functor , Qt::ConnectionType type = Qt::AutoConnection)
typename std::enable_if<!QtPrivate::FunctionPointer<Functor>::IsPointerToMemberFunction && !std::is_same<const char *, Functor>::value, QMetaObject::Connection>::type connectToState (const QString & scxmlStateName , const QObject * context , Functor functor , Qt::ConnectionType type = Qt::AutoConnection)
QScxmlDataModel * dataModel () const
QVariantMap initialValues ()
QList<QScxmlInvokableService *> invokedServices () const
bool isActive (const QString & scxmlStateName ) const
bool isDispatchableTarget (const QString & target ) const
bool isInitialized () const
bool isInvoked () const
bool isRunning () const
QScxmlCompiler::Loader * loader () const
QString name () const
QList<QScxmlError> parseErrors () const
QString sessionId () const
void setDataModel (QScxmlDataModel * model )
void setInitialValues (const QVariantMap & initialValues )
void setLoader (QScxmlCompiler::Loader * loader )
void setRunning (bool running )
void setTableData (QScxmlTableData * tableData )
QStringList stateNames (bool compress = true) const
void submitEvent (QScxmlEvent * event )
void submitEvent (const QString & eventName )
void submitEvent (const QString & eventName , const QVariant & data )
QScxmlTableData * tableData () const

公共槽

bool init ()
void start ()
void stop ()

信号

void dataModelChanged (QScxmlDataModel * model )
void finished ()
void initialValuesChanged (const QVariantMap & initialValues )
void initializedChanged (bool initialized )
void invokedServicesChanged (const QList<QScxmlInvokableService *> & invokedServices )
void loaderChanged (QScxmlCompiler::Loader * loader )
void log (const QString & label , const QString & msg )
void reachedStableState ()
void runningChanged (bool running )
void tableDataChanged (QScxmlTableData * tableData )

静态公共成员

QScxmlStateMachine * fromData (QIODevice * data , const QString & fileName = QString())
QScxmlStateMachine * fromFile (const QString & fileName )
std::function<void (bool)> onEntry (const QObject * receiver , const char * method )
std::function<void (bool)> onEntry (Functor functor )
std::function<void (bool)> onEntry (const typename QtPrivate::FunctionPointer<PointerToMemberFunction>::Object * receiver , PointerToMemberFunction method )
std::function<void (bool)> onExit (const QObject * receiver , const char * method )
std::function<void (bool)> onExit (Functor functor )
std::function<void (bool)> onExit (const typename QtPrivate::FunctionPointer<PointerToMemberFunction>::Object * receiver , PointerToMemberFunction method )

保护函数

bool isActive (int stateIndex ) const

详细描述

QScxmlStateMachine is an implementation of the SCXML (状态图表 XML) .

All states that are defined in the SCXML file are accessible as properties of QScxmlStateMachine. These properties are boolean values and indicate whether the state is active or inactive.

注意: The QScxmlStateMachine needs a QEventLoop to work correctly. The event loop is used to implement the delay attribute for events and to schedule the processing of a state machine when events are received from nested (or parent) state machines.

特性文档编制

[bindable] dataModel : QScxmlDataModel *

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

This property holds the data model to be used for this state machine.

SCXML data models are described in SCXML Specification - 5 Data Model and Data Manipulation . For more information about supported data models, see SCXML 合规 .

Changing the data model when the state machine has been initialized is not specified in the SCXML standard and leads to undefined behavior.

另请参阅 QScxmlDataModel , QScxmlNullDataModel ,和 QScxmlCppDataModel .

[bindable] initialValues : QVariantMap

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

This property holds the initial values to be used for setting up the data model.

另请参阅 QScxmlStateMachine::init () 和 QScxmlDataModel .

[bindable read-only] initialized : bool

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

This property holds whether the state machine has been initialized.

It is true if the state machine has been initialized, false 否则。

另请参阅 QScxmlStateMachine::init () 和 QScxmlDataModel .

[read-only] invoked : const bool

This property holds whether the state machine was invoked from an outer state machine.

true when the state machine was started as a service with the <invoke> element, false 否则。

访问函数:

bool isInvoked () const

[bindable read-only] invokedServices : QList < QScxmlInvokableService *>

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

This property holds a list of SCXML services that were invoked from the main state machine (possibly recursively).

[bindable] loader : QScxmlCompiler::Loader *

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

This property holds the loader that is currently used to resolve and load URIs for the state machine.

[read-only] name : const QString

This property holds the name of the state machine as set by the name 属性在 <scxml> 标签。

访问函数:

QString name () const

[read-only] parseErrors : const QList < QScxmlError >

This property holds the list of parse errors that occurred while creating a state machine from an SCXML file.

访问函数:

QList<QScxmlError> parseErrors () const

running : bool

This property holds the running state of this state machine

访问函数:

bool isRunning () const
void setRunning (bool running )

通知程序信号:

void runningChanged (bool running )

另请参阅 start ().

[read-only] sessionId : const QString

This property holds the session ID of the current state machine.

The session ID is used for message routing between parent and child state machines. If a state machine is started by an <invoke> element, any event it sends will have the invokeid field set to the session ID. The state machine will use the origin of an event (which is set by the target or targetexpr attribute in a <send> element) to dispatch messages to the correct child state machine.

访问函数:

QString sessionId () const

另请参阅 QScxmlEvent::invokeId ().

[bindable] tableData : QScxmlTableData *

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

This property holds the table data that is used when generating C++ from an SCXML file.

The class implementing the state machine will use this property to assign the generated table data. The state machine does not assume ownership of the table data.

成员函数文档编制

[invokable] QStringList QScxmlStateMachine:: activeStateNames ( bool compress = true) const

Retrieves a list of state names of all active states.

When a state is active, all its parent states are active by definition. When compress is true (the default), the parent states will be filtered out and only the leaf states will be returned. When it is false , the full list of active states will be returned.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[invokable] void QScxmlStateMachine:: cancelDelayedEvent (const QString & sendId )

Cancels a delayed event with the specified sendId .

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

QMetaObject::Connection QScxmlStateMachine:: connectToEvent (const QString & scxmlEventSpec , const QObject * receiver , const char * method , Qt::ConnectionType type = Qt::AutoConnection)

Creates a connection of the specified type from the event specified by scxmlEventSpecmethodreceiver object. The receiver's method may take a QScxmlEvent as a parameter. For example:

void mySlot(const QScxmlEvent &event);
					

In contrast to event specifications in SCXML documents, spaces are not allowed in the scxmlEventSpec here. In order to connect to multiple events with different prefixes, connectToEvent() has to be called multiple times.

Returns a handle to the connection, which can be used later to disconnect.

template <typename PointerToMemberFunction> QMetaObject::Connection QScxmlStateMachine:: connectToEvent (const QString & scxmlEventSpec , const typename QtPrivate::FunctionPointer < PointerToMemberFunction > ::Object * receiver , PointerToMemberFunction method , Qt::ConnectionType type = Qt::AutoConnection)

创建连接为给定 type from the event specified by scxmlEventSpec to methodreceiver 对象。

The receiver's method 必须接受 QScxmlEvent as a parameter.

In contrast to event specifications in SCXML documents, spaces are not allowed in the scxmlEventSpec here. In order to connect to multiple events with different prefixes, connectToEvent() has to be called multiple times.

Returns a handle to the connection, which can be used later to disconnect.

template <typename Functor> typename std::enable_if <! QtPrivate::FunctionPointer < Functor > ::IsPointerToMemberFunction && ! std::is_same <const char *, Functor > ::value , QMetaObject::Connection > ::type QScxmlStateMachine:: connectToEvent (const QString & scxmlEventSpec , Functor functor , Qt::ConnectionType type = Qt::AutoConnection)

创建连接为给定 type from the event specified by scxmlEventSpec to functor .

The functor 必须接受 QScxmlEvent as a parameter.

In contrast to event specifications in SCXML documents, spaces are not allowed in the scxmlEventSpec here. In order to connect to multiple events with different prefixes, connectToEvent() has to be called multiple times.

Returns a handle to the connection, which can be used later to disconnect.

template <typename Functor> typename std::enable_if <! QtPrivate::FunctionPointer < Functor > ::IsPointerToMemberFunction && ! std::is_same <const char *, Functor > ::value , QMetaObject::Connection > ::type QScxmlStateMachine:: connectToEvent (const QString & scxmlEventSpec , const QObject * context , Functor functor , Qt::ConnectionType type = Qt::AutoConnection)

创建连接为给定 type from the event specified by scxmlEventSpec to functor 使用 context as context.

The functor 必须接受 QScxmlEvent as a parameter.

In contrast to event specifications in SCXML documents, spaces are not allowed in the scxmlEventSpec here. In order to connect to multiple events with different prefixes, connectToEvent() has to be called multiple times.

Returns a handle to the connection, which can be used later to disconnect.

QMetaObject::Connection QScxmlStateMachine:: connectToState (const QString & scxmlStateName , const QObject * receiver , const char * method , Qt::ConnectionType type = Qt::AutoConnection)

创建连接为给定 type from the state identified by scxmlStateNamemethodreceiver object. The receiver's method may take a boolean argument that indicates whether the state connected became active or inactive. For example:

void mySlot(bool active);
					

Returns a handle to the connection, which can be used later to disconnect.

template <typename PointerToMemberFunction> QMetaObject::Connection QScxmlStateMachine:: connectToState (const QString & scxmlStateName , const typename QtPrivate::FunctionPointer < PointerToMemberFunction > ::Object * receiver , PointerToMemberFunction method , Qt::ConnectionType type = Qt::AutoConnection)

创建连接为给定 type from the state specified by scxmlStateName to methodreceiver 对象。

The receiver's method must take a boolean argument that indicates whether the state connected became active or inactive.

Returns a handle to the connection, which can be used later to disconnect.

template <typename Functor> typename std::enable_if <! QtPrivate::FunctionPointer < Functor > ::IsPointerToMemberFunction && ! std::is_same <const char *, Functor > ::value , QMetaObject::Connection > ::type QScxmlStateMachine:: connectToState (const QString & scxmlStateName , Functor functor , Qt::ConnectionType type = Qt::AutoConnection)

创建连接为给定 type from the state specified by scxmlStateName to functor .

The functor must take a boolean argument that indicates whether the state connected became active or inactive.

Returns a handle to the connection, which can be used later to disconnect.

template <typename Functor> typename std::enable_if <! QtPrivate::FunctionPointer < Functor > ::IsPointerToMemberFunction && ! std::is_same <const char *, Functor > ::value , QMetaObject::Connection > ::type QScxmlStateMachine:: connectToState (const QString & scxmlStateName , const QObject * context , Functor functor , Qt::ConnectionType type = Qt::AutoConnection)

创建连接为给定 type from the state specified by scxmlStateName to functor 使用 context as context.

The functor must take a boolean argument that indicates whether the state connected became active or inactive.

Returns a handle to the connection, which can be used later to disconnect.

QScxmlDataModel *QScxmlStateMachine:: dataModel () const

Returns the data model used by the state machine.

注意: Getter function for property dataModel.

另请参阅 setDataModel ().

[signal] void QScxmlStateMachine:: finished ()

This signal is emitted when the state machine reaches a top-level final state.

另请参阅 running .

[static] QScxmlStateMachine *QScxmlStateMachine:: fromData ( QIODevice * data , const QString & fileName = QString())

Creates a state machine by reading from the QIODevice 指定通过 data .

This method will always return a state machine. If errors occur while reading the SCXML file, fileName , the state machine cannot be started. The errors can be retrieved by calling the parseErrors () 方法。

另请参阅 parseErrors ().

[static] QScxmlStateMachine *QScxmlStateMachine:: fromFile (const QString & fileName )

Creates a state machine from the SCXML file specified by fileName .

This method will always return a state machine. If errors occur while reading the SCXML file, the state machine cannot be started. The errors can be retrieved by calling the parseErrors () 方法。

另请参阅 parseErrors ().

[slot] bool QScxmlStateMachine:: init ()

Initializes the state machine.

State machine initialization consists of calling QScxmlDataModel::setup (), setting the initial values for <data> elements, and executing any <script> tags of the <scxml> tag. The initial data values are taken from the initialValues 特性。

返回 false if parse errors occur or if any of the initialization steps fail. Returns true 否则。

[invokable] bool QScxmlStateMachine:: isActive (const QString & scxmlStateName ) const

返回 true if the state specified by scxmlStateName is active, false 否则。

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[protected] bool QScxmlStateMachine:: isActive ( int stateIndex ) const

返回 true if the state with the ID stateIndex is active.

This method is part of the interface to the compiled representation of SCXML state machines. It should only be used internally and by state machines compiled from SCXML documents.

[invokable] bool QScxmlStateMachine:: isDispatchableTarget (const QString & target ) const

返回 true if a message to target can be dispatched by this state machine.

Valid targets are:

  • #_parent for the parent state machine if the current state machine is started by <invoke>
  • #_internal for the current state machine
  • #_scxml_sessionid ,其中 sessionid is the session ID of the current state machine
  • #_servicename ,其中 servicename is the ID or name of a service started with <invoke> by this state machine

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

bool QScxmlStateMachine:: isRunning () const

返回 true if the state machine is running, false 否则。

注意: getter 函数对于特性 running .

另请参阅 setRunning () 和 runningChanged ().

[signal] void QScxmlStateMachine:: log (const QString & label , const QString & msg )

This signal is emitted if a <log> tag is used in the SCXML. label is the value of the label 属性在 <log> 标签。 msg is the value of the evaluated expr 属性在 <log> tag. If there is no expr attribute, a null string will be returned.

[static] std::function < void ( bool )> QScxmlStateMachine:: onEntry (const QObject * receiver , const char * method )

Returns a functor that accepts a boolean argument and calls the given method on receiver 使用 QMetaObject::invokeMethod () if that argument is true and receiver has not been deleted, yet.

给定 method must not accept any arguments. method is the plain method name, not enclosed in SIGNAL() or SLOT() .

This is useful to wrap handlers for connectToState () that should only be executed when the state is entered.

[static] template <typename Functor> std::function < void ( bool )> QScxmlStateMachine:: onEntry ( Functor functor )

Returns a functor that accepts a boolean argument and calls the given functor if that argument is true . The given functor must not accept any arguments.

This is useful to wrap handlers for connectToState () that should only be executed when the state is entered.

[static] template <typename PointerToMemberFunction> std::function < void ( bool )> QScxmlStateMachine:: onEntry (const typename QtPrivate::FunctionPointer < PointerToMemberFunction > ::Object * receiver , PointerToMemberFunction method )

Returns a functor that accepts a boolean argument and calls the given method on receiver if that argument is true receiver has not been deleted, yet. The given method must not accept any arguments.

This is useful to wrap handlers for connectToState () that should only be executed when the state is entered.

[static] std::function < void ( bool )> QScxmlStateMachine:: onExit (const QObject * receiver , const char * method )

Returns a functor that accepts a boolean argument and calls the given method on receiver 使用 QMetaObject::invokeMethod () if that argument is false and receiver has not been deleted, yet.

给定 method must not accept any arguments. method is the plain method name, not enclosed in SIGNAL(...) or SLOT(...).

This is useful to wrap handlers for connectToState () that should only be executed when the state is left.

[static] template <typename Functor> std::function < void ( bool )> QScxmlStateMachine:: onExit ( Functor functor )

Returns a functor that accepts a boolean argument and calls the given functor if that argument is false . The given functor must not accept any arguments.

This is useful to wrap handlers for connectToState () that should only be executed when the state is left.

[static] template <typename PointerToMemberFunction> std::function < void ( bool )> QScxmlStateMachine:: onExit (const typename QtPrivate::FunctionPointer < PointerToMemberFunction > ::Object * receiver , PointerToMemberFunction method )

Returns a functor that accepts a boolean argument and calls the given method on receiver if that argument is false receiver has not been deleted, yet. The given method must not accept any arguments.

This is useful to wrap handlers for connectToState () that should only be executed when the state is left.

[signal] void QScxmlStateMachine:: reachedStableState ()

This signal is emitted when the event queue is empty at the end of a macro step or when a final state is reached.

[signal] void QScxmlStateMachine:: runningChanged ( bool running )

此信号被发射当 running property is changed with running 作为自变量。

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

void QScxmlStateMachine:: setDataModel ( QScxmlDataModel * model )

Sets the data model for this state machine to model . There is a 1:1 relation between state machines and models. After setting the model once you cannot change it anymore. Any further attempts to set the model using this method will be ignored.

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

另请参阅 dataModel ().

void QScxmlStateMachine:: setRunning ( bool running )

Starts the state machine if running is true , or stops it otherwise.

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

另请参阅 start (), stop (), isRunning (),和 runningChanged ().

[slot] void QScxmlStateMachine:: start ()

Starts this state machine. The machine will reset its configuration and transition to the initial state. When a final top-level state is entered, the machine will emit the finished () 信号。

注意: A state machine will not run without a running event loop, such as the main application event loop started with QCoreApplication::exec () 或 QApplication::exec ().

另请参阅 runningChanged (), setRunning (), stop (),和 finished ().

[invokable] QStringList QScxmlStateMachine:: stateNames ( bool compress = true) const

Retrieves a list of state names of all states.

compress is true (the default), the states that contain child states will be filtered out and only the leaf states will be returned. When it is false , the full list of all states will be returned.

The returned list does not contain the states of possible nested state machines.

注意: The order of the state names in the list is the order in which the states occurred in the SCXML document.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[slot] void QScxmlStateMachine:: stop ()

Stops this state machine. The machine will not execute any further state transitions. Its running property is set to false .

另请参阅 runningChanged (), start (),和 setRunning ().

[invokable] void QScxmlStateMachine:: submitEvent ( QScxmlEvent * event )

Submits the SCXML event event to the internal or external event queue depending on the priority of the event.

When a delay is set, the event will be queued for delivery after the timeout has passed. The state machine takes ownership of event and deletes it after processing.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[invokable] void QScxmlStateMachine:: submitEvent (const QString & eventName )

A utility method to create and submit an external event with the specified eventName as the name.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .

[invokable] void QScxmlStateMachine:: submitEvent (const QString & eventName , const QVariant & data )

A utility method to create and submit an external event with the specified eventName as the name and data as the payload data.

注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .