SCXML 호출

컴파일된 중첩 상태 머신을 호출합니다.

Invoke는 생성된 중첩 상태 머신과 함께 <invoke> 요소를 사용하는 방법을 보여 주며, 여기서 SCXML 파일은 C++ 클래스로 컴파일됩니다. <invoke> 요소는 외부 서비스의 인스턴스를 만드는 데 사용됩니다.

예제 실행하기

에서 예제를 실행하려면 Qt Creator에서 Welcome 모드를 열고 Examples 에서 예제를 선택합니다. 자세한 내용은 예제 빌드 및 실행하기를 참조하세요.

상태 머신 호출하기

statemachine.scxml에서 이름이 DirectionsStateMachine인 상태 머신을 http://www.w3.org/TR/scxml/ 유형으로 지정하여 호출합니다:

<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 모듈에 대해 링크합니다.

invoke.pro에 추가합니다:
QT += qml scxml

그런 다음 컴파일할 스테이트 머신을 지정합니다:

STATECHARTS = statemachine.scxml
컴파일할 상태 머신을 지정합니다:
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
)

statecharts 또는 qt6_add_statecharts 지시어는 Qt SCXML 컴파일러( qscxmlc)를 호출하고, 이 컴파일러는 자동으로 실행되어 statemachine.hstatemachine.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
    }

예제 프로젝트 @ code.qt.io

© 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.