SignalTransition QML Type
SignalTransition 类型提供基于 Qt 信号的过渡。更多内容...
| Import Statement: | import QtQml.StateMachine 6.12 |
| Inherits: |
属性
详细说明
SignalTransition 是Qt State Machine QML API 的一部分。
使用示例
import QtQuick
import QtQml.StateMachine as DSM
Rectangle {
DSM.StateMachine {
id: stateMachine
initialState: state
running: true
DSM.State {
id: state
DSM.SignalTransition {
targetState: finalState
signal: button.clicked
guard: guardButton.checked
}
}
DSM.FinalState {
id: finalState
}
onFinished: Qt.quit()
}
Row {
spacing: 2
Button {
id: button
text: "Finish state"
}
Button {
id: guardButton
checkable: true
text: checked ? "Press to block the SignalTransition" : "Press to unblock the SignalTransition"
}
}
}另请参阅 StateMachine 、FinalState 以及TimeoutTransition 。
属性文档
guard : bool
守护条件通过仅在评估结果为真时允许状态转换、在评估结果为假时禁止状态转换,从而影响状态机的行为。
当与该信号转换相关的信号被发出时,将对守护条件进行求值。在守护条件中,可以像下面的示例所示那样使用该信号的参数。
import QtQuick
import QtQml.StateMachine as DSM
Rectangle {
Button {
anchors.fill: parent
id: button
DSM.StateMachine {
DSM.State {
DSM.SignalTransition {
targetState: finalState
signal: button.mysignal
// the guard condition uses the mystr string argument from mysignal
guard: mystr == "test"
}
}
DSM.FinalState {
id: finalState
}
}
// define the signal the SignalTransition is connected with
signal mysignal(mystr: string)
// on clicking the button emit the signal with a single string argument
onClicked: button.mysignal("test")
}
}另请参阅 signal 。
signal : signal
与该信号跳变相关的信号。
import QtQuick
import QtQml.StateMachine as DSM
Rectangle {
Button {
anchors.fill: parent
id: button
DSM.StateMachine {
DSM.State {
DSM.SignalTransition {
targetState: finalState
signal: button.clicked
}
}
DSM.FinalState {
id: finalState
}
}
}
}© 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.