このページでは

HistoryState QML Type

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

Import Statement: import QtQml.StateMachine 6.12
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 ネストされた状態が記録されます。この場合、履歴状態をターゲットとする遷移は、親状態が最後に終了した際にあった、最も深くネストされた子孫の状態に到達します。

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