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() }
}
}
}
}
実行結果

※Linux Mint 18.2 & Qt 5.9.1使用