SCXML 計算機
SCXML 仕様書の Calculator の例を実装したアプリケーションです。
Calculator は Qt SCXML を使用して SCXML 仕様書に示されたCalculator の例を実装します。
ステートマシンはstatemachine.scxmlファイルで指定され、CalculatorStateMachine
クラスにコンパイルされます。ユーザインタフェースはQt Quick を使用して作成されます。
例の実行
からサンプルを実行するには Qt Creatorからサンプルを実行するには、Welcome モードを開き、Examples からサンプルを選択します。詳細については、「例の構築と実行」を参照してください。
ステート・マシンのインスタンス化
生成されたCalculatorStateMachine
クラスを、calculator-qml.hファイルでQML型として宣言し、QMLで利用できるようにします:
struct CalculatorStateMachineRegistration { Q_GADGET QML_FOREIGN(CalculatorStateMachine) QML_NAMED_ELEMENT(CalculatorStateMachine) QML_ADDED_IN_VERSION(1, 0) };
CalculatorStateMachineをインスタンス化し、updateDisplay
イベントをリッスンします。このイベントが発生すると、電卓ディスプレイのテキストを変更します:
CalculatorStateMachine { id: statemachine running: true EventConnection { events: ["updateDisplay"] onOccurred: (event)=> resultText.text = event.data.display } }
ユーザーが電卓のボタンを押すと、ボタンがステートマシンにイベントを送信します:
Button { id: resultButton x: 3 * width y: parent.height / 5 textHeight: y - 2 fontHeight: 0.4 width: parent.width / 4 height: y * 4 color: pressed ? "#e0b91c" : "#face20" text: "=" onClicked: statemachine.submitEvent("EQUALS") }
© 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.