Sur cette page

SignalTransition QML Type

Le type SignalTransition fournit une transition basée sur un signal Qt. Plus d'informations...

Import Statement: import QtQml.StateMachine 6.11
Inherits:

QSignalTransition

Propriétés

Description détaillée

SignalTransition fait partie de l'API QMLQt State Machine .

Exemple d'utilisation

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"
        }
    }
}

Voir également StateMachine, FinalState, et TimeoutTransition.

Documentation sur les propriétés

guard : bool

Les conditions de garde affectent le comportement d'une machine d'état en activant les transitions uniquement lorsqu'elles sont évaluées à vrai et en les désactivant lorsqu'elles sont évaluées à faux.

Lorsque le signal associé à cette transition de signal est émis, la condition de garde est évaluée. Dans la condition de garde, les arguments du signal peuvent être utilisés comme le montre l'exemple ci-dessous.

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")
    }
}

Voir aussi signal.

signal : signal

Le signal associé à cette transition de 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.