HistoryState QML Type

HistoryState型は、以前にアクティブだったサブステートに戻る手段を提供する。詳細...

Import Statement: import QtQml.StateMachine 6.8
Inherits:

QAbstractState

プロパティ

詳細説明

ヒストリー状態とは、親状態が最後に終了したときの子状態を表す擬似状態である。ヒストリ状態を遷移先とする遷移は、実際には親状態の他の子状態のいずれかへの遷移である。HistoryState はQt State Machine QML API の一部です。

defaultState プロパティを使用して、親状態に一度も入ったことがない場合に入るべき状態を設定します。

使用例

import QtQuick
import QtQml.StateMachine as DSM

Rectangle {
    Button {
        anchors.fill: parent
        id: button
        text: "Press me"
        DSM.StateMachine {
            id: stateMachine
            initialState: parentState
            running: true
            DSM.State {
                id: parentState
                initialState: child2
                onEntered: console.log("parentState entered")
                onExited: console.log("parentState exited")
                DSM.State {
                    id: child1
                    onEntered: console.log("child1 entered")
                    onExited: console.log("child1 exited")
                }
                DSM.State {
                    id: child2
                    onEntered: console.log("child2 entered")
                    onExited: console.log("child2 exited")
                }
                DSM.HistoryState {
                    id: historyState
                    defaultState: child1
                }
                DSM.SignalTransition {
                    targetState: historyState

                    // Clicking the button will cause the state machine to enter the child state
                    // that parentState was in the last time parentState was exited, or the history state's default
                    // state if parentState has never been entered.
                    signal: button.clicked
                }
            }
        }
    }
}

デフォルトでは、履歴状態は浅く、つまりネストした状態を記憶しません。これは、historyType プロパティで設定できます。

StateMachine およびStateも参照のこと

プロパティの説明

defaultState : QAbstractState

この履歴状態のデフォルト状態。

デフォルト状態は、親状態が一度も入力されたことがない場合に遷移する状態を示す。


historyType : enumeration

この履歴状態が記録する履歴のタイプ。

このプロパティのデフォルト値はHistoryState.ShallowHistory です。

この列挙型は、HistoryState が記録する履歴のタイプを指定する。

  • HistoryState.ShallowHistory 親状態の直接の子状態のみが記録される。この場合、ヒストリ・ステートをターゲットとする遷移は、親ステートが最後に終了したときの直前の子ステートで終了します。これがデフォルトです。
  • HistoryState.DeepHistory 入れ子状態が記録されます。この場合、ヒストリ状態をターゲットとするトランジションは、最後に終了したときに親がいた、最も深くネストされた子孫の状態で終了します。

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