本页内容

State QML Type

为StateMachine 提供了一个通用状态。更多内容...

Import Statement: import QtQml.StateMachine 6.12
Inherits:

QAbstractState

Inherited By:

StateMachine

属性

信号

详细说明

状态对象既可以拥有子状态,也可以与其他状态之间建立转换关系。状态是Qt State Machine QML API的一部分

具有子状态的状态

childMode 属性决定了如何处理子状态。对于非并行状态组,必须使用initialState 属性来设置初始状态。子状态是互斥状态,当父状态是过渡的目标时,状态机需要知道应进入哪个子状态。

当进入最终子状态(FinalState )时,该状态会发出State::finished()信号。

errorState 用于设置状态的错误状态。错误状态是指在尝试进入该状态时检测到错误(例如因未设置初始状态)时,状态机将转入的状态。

用法示例

import QtQuick
import QtQml.StateMachine as DSM

Rectangle {
    DSM.StateMachine {
        id: stateMachine
        initialState: state
        running: true
        DSM.State {
            id: state
        }
    }
}

另请参阅 StateMachine 和FinalState 。

属性文档

childMode : enumeration

此状态的子模式

该属性的默认值为QState.ExclusiveStates。

此枚举指定了如何处理状态的子状态:

  • QState.ExclusiveStates 子状态彼此互斥,必须通过设置initialState 属性来指定初始状态。
  • QState.ParallelStates 子状态是并行的。当进入父状态时,其所有子状态将并行进入。

errorState : QAbstractState

该状态的错误状态。

initialState : QAbstractState

该状态的初始状态(其子状态之一)。

信号文档

finished()

当进入该状态的最终子状态时,会发出此信号。

注意: 相应的处理程序 为onFinished 。

另请参阅 QAbstractState::active 、QAbstractState::entered 以及QAbstractState::exited 。

© 2026 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.