SCXML呼び出し
コンパイルされたネストされたステートマシンを起動します。
Invokeは生成されたネストされたステートマシンで<invoke>
要素を使用する方法を示します。ここで、SCXML ファイルは C++ クラスにコンパイルされます。<invoke>
要素は外部サービスのインスタンスを生成するために使用されます。
例の実行
から例を実行するには Qt Creatorからサンプルを実行するには、Welcome モードを開き、Examples からサンプルを選択します。詳細については、「例の構築と実行」を参照してください。
ステートマシンの起動
statemachine.scxmlで、http://www.w3.org/TR/scxml/型のDirectionsStateMachineという名前のステートマシンを指定して起動します:
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" name="DirectionsStateMachine" initial="anyplace" > <state id="anyplace"> <transition event="goNowhere" target="nowhere"/> <transition event="goSomewhere" target="somewhere"/> <state id="nowhere"/> <state id="somewhere"> <invoke type="http://www.w3.org/TR/scxml/"> <content> <scxml name="anywhere" version="1.0"> <state id="here"> <transition event="goThere" target="there"/> </state> <state id="there"> <transition event="goHere" target="here"/> </state> </scxml> </content> </invoke> </state> </state> </scxml>
ステートマシンのコンパイル
サンプルのビルドファイルに以下の行を追加して、Qt SCXML モジュールとリンクします。
qmakeを使用する場合は、invoke.proを使用します:
QT += qml scxml
次に、コンパイルするステートマシンを指定します:
STATECHARTS = statemachine.scxml
cmakeを使用する場合は、CMakeLists.txt:
find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Scxml) target_link_libraries(invoke PRIVATE Qt6::Core Qt6::Gui Qt6::Qml Qt6::Scxml )
次に、コンパイルするステートマシンを指定します:
qt6_add_statecharts(invoke statemachine.scxml )
statechartディレクティブSTATECHARTSまたはqt6_add_statechartsにより、Qt SCXML Compiler,qscxmlc
。自動的に実行され、statemachine.hと statemachine.cppが生成され、コンパイル用のヘッダーとソースとして適切に追加されます。
QML要素としてのステートマシンの宣言
ステートマシンは以下のようにQML要素として宣言されます:
struct DirectionsStateMachineRegistration { Q_GADGET QML_FOREIGN(DirectionsStateMachine) QML_NAMED_ELEMENT(DirectionsStateMachine) QML_ADDED_IN_VERSION(1, 0) };
ステートマシンのインスタンス化
生成されたDirectionsStateMachine
要素を、MainView.qmlファイルで以下のようにインスタンス化します:
DirectionsStateMachine { id: stateMachine running: true }
© 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.