ScxmlStateMachine QML Type
为从 SCXML 文件创建的状态机提供接口。更多
Import Statement: | import QtScxml 6.9 |
In C++: | QScxmlStateMachine |
属性
- dataModel : ScxmlDataModel
- initialValues : var
- initialized : bool
- invoked : bool
- invokedServices : list
- loader : Loader
- name : string
- parseErrors : var
- running : bool
- sessionId : string
信号
- finished()
- log(string label, string msg)
- reachedStableState()
方法
- activeStateNames(bool compress)
- cancelDelayedEvent(string sendId)
- init()
- isActive(string scxmlStateName)
- isDispatchableTarget(string target)
- start()
- stateNames(bool compress)
- stop()
- submitEvent(event)
- submitEvent(string eventName, var data)
详细说明
ScxmlStateMachine 类型是状态图 XML(SCXML)的一种实现。
SCXML 文件中定义的所有状态都可以作为该类型的属性访问。这些属性都是布尔值,表示状态是激活状态还是非激活状态。
属性文档
dataModel : ScxmlDataModel |
用于此状态机的数据模型。
SCXML 数据模型在《SCXML 规范 - 5 数据模型和数据处理》中有描述。有关支持的数据模型的更多信息,请参阅SCXML Compliance。
SCXML 标准中没有规定在状态机initialized 时更改数据模型,这将导致未定义的行为。
另请参阅 QScxmlDataModel,QScxmlNullDataModel, 和QScxmlCppDataModel 。
initialValues : var |
用于设置数据模型的初始值。
initialized : bool |
如果状态机已被初始化,该只读属性将设为true
,否则设为false
。
invoked : bool |
状态机是否从外部状态机调用。
如果状态机是通过<invoke>
元素作为服务启动的,则此只读属性被设为true
,否则为false
。
invokedServices : list |
从主状态机(可能是递归的)调用的 SCXML 服务列表。
loader : Loader |
当前用于解析和加载状态机 URI 的加载器。
name : string |
由<scxml>
标签name属性设置的状态机名称。
parseErrors : var |
从 SCXML 文件创建状态机时出现的解析错误列表。
running : bool |
状态机的运行状态。
sessionId : string |
当前状态机的会话 ID。
会话 ID 用于父状态机和子状态机之间的报文路由。如果状态机是由<invoke>
元素启动的,那么它发送的任何事件的invokeid
字段都将设置为会话 ID。状态机将使用事件的起源(由<send>
元素中的target或targetexpr属性设置)向正确的子状态机发送消息。
信号文档
finished() |
该信号在状态机达到顶层最终状态时发出。
相应的信号处理程序是onFinished()
。
注: 相应的处理程序是onFinished
。
log(string label, string msg) |
如果 SCXML 中使用了<log>
标签,就会发出该信号。label 是<log>
标签的label属性的值。msg 是<log>
标签的已评估expr属性的值。如果没有expr属性,将返回空字符串。
相应的信号处理程序是onLog()
。
注: 相应的处理程序是onLog
。
reachedStableState() |
当宏步骤结束或达到最终状态时,事件队列为空时,将发出该信号。
相应的信号处理程序是onreachedStableState()
。
注: 相应的处理程序是onReachedStableState
。
方法文档
activeStateNames(bool compress) |
读取所有活动状态的状态名称列表。
根据定义,当一个状态处于活动状态时,它的所有父级状态都处于活动状态。当compress 为true
(默认值)时,父状态会被过滤掉,只返回叶状态。false
时,将返回全部活动状态列表。
cancelDelayedEvent(string sendId) |
使用指定的sendId 取消延迟事件。
init() |
通过设置<data>
元素的初始值和执行<scxml>
标签的任何<script>
标签来初始化状态机。初始数据值取自initialValues 属性。
如果出现解析错误或任何初始化步骤失败,则返回false
。否则返回true
。
isActive(string scxmlStateName) |
如果scxmlStateName 指定的状态处于活动状态,则返回true
,否则返回false
。
isDispatchableTarget(string target) |
如果状态机可以向target 发送消息,则返回true
。
有效目标是
#_parent
父状态机,如果当前状态机是由父状态机启动的<invoke>
#_internal
当前状态机#_scxml_sessionid
其中sessionid
是当前状态机的会话 ID。#_servicename
其中servicename
是本状态机通过<invoke>
启动的服务的 ID 或名称。
stateNames(bool compress) |
读取所有状态的状态名列表。
当compress 为true
(默认值)时,会过滤掉包含子状态的状态,只返回叶子状态。当false
时,将返回所有状态的完整列表。
返回的列表不包含可能嵌套的状态机的状态。
注意: 列表中状态名称的顺序是状态在 SCXML 文档中出现的顺序。
submitEvent(event) |
根据事件的优先级,将 SCXML 事件event 提交到内部或外部事件队列。
如果设置了延时,事件将在超时后排队交付。状态机拥有事件的所有权,并在处理后将其删除。
另请参阅 QScxmlEvent 。
submitEvent(string eventName, var data) |
创建和提交外部事件的实用方法,其名称为指定的eventName ,有效载荷数据为data (可选)。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.