이 페이지에서

SCXML 호출

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

네 개의 패널로 이루어진 창: ‘아무 데도 가지 않기’, ‘어딘가로 가기’, ‘저기로 가기’, ‘이리로 가기’

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

예제 실행

다음 경로에서 예제를 실행할 수 있습니다.

상태 머신 호출

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
)

상태 차트 지시어인 STATECHARTS 또는 qt6_add_statecharts는 Qt SCXML 컴파일러( qscxmlc)를 호출하며, 이 컴파일러는 자동으로 실행되어 statemachine.h와 statemachine.cpp 파일을 생성합니다. 생성된 파일들은 컴파일을 위해 헤더 파일과 소스 파일로 적절히 추가됩니다.

상태 머신을 QML 요소로 선언하기

상태 머신은 다음과 같이 QML 요소로 선언됩니다:

struct DirectionsStateMachineRegistration
{
    Q_GADGET
    QML_FOREIGN(DirectionsStateMachine)
    QML_NAMED_ELEMENT(DirectionsStateMachine)
    QML_ADDED_IN_VERSION(1, 0)
};

상태 머신 인스턴스화

MainView.qml 파일에서 생성된 DirectionsStateMachine 요소를 다음과 같이 인스턴스화합니다:

    DirectionsStateMachine {
        id: stateMachine
        running: true
    }

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

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