0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

TimeoutTransitionサンプル

Posted at

TimeoutTransitionのサンプル

テスト用のQML

import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQml.StateMachine 1.0 as DSM
import QtMultimedia 5.9

ApplicationWindow {
    id: root
    visible: true
    width: 640
    height: 480
    title: qsTr("TimeoutTransitionサンプル")

    Audio { id: clickSound; source: "Sounds/btn01.mp3" }
    Audio { id: finishSound; source: "Sounds/btn02.mp3" }

    Row {
        spacing: 2

        Rectangle { id: colorBox; width: root.width / 2; height: root.height }

        // ボタンのクリックで stateMachine の動作を開始する
        Button {
            id: button
            width: root.width / 2
            height: root.height
            text: "Finish state"
            enabled: !stateMachine.running
            onClicked: { stateMachine.running = true; clickSound.play() }

            // StateMachine 定義
            DSM.StateMachine {
                id: stateMachine
                initialState: state
                running: false

                // 初期状態
                DSM.State {
                    id: state

                    // TimeoutTransition 定義
                    DSM.TimeoutTransition {
                        targetState: finalState
                        timeout: 5000           // 5秒後に状態変更
                    }
                }

                // FinalState 定義
                DSM.FinalState {
                    id: finalState
                }

                // Rectangle の色を変えて音を鳴らす
                onFinished: { colorBox.color = "red"; finishSound.play() }
            }
        }
    }
}

実行結果

SignalTransitionサンプル動画
※Linux Mint 18.2 & Qt 5.9.1使用

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?