TimeoutTransitionサンプル
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() }
}
}
}
}
実行結果
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() }
}
}
}
}
Author And Source
この問題について(TimeoutTransitionサンプル), 我々は、より多くの情報をここで見つけました https://qiita.com/Taro3/items/7eb64e1b3a2b1a314d5b著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .