QT_GENERATE_FOREIGN_QML_TYPES

한 대상의 유형을 QML 모듈에 등록합니다.

이 명령은 Qt6 패키지의 Qml 구성 요소에 정의되어 있으며, 다음과 같이 로드할 수 있습니다:

find_package(Qt6 REQUIRED COMPONENTS Qml)

개요

qt_generate_foreign_qml_types(
    source_target
    destination_qml_target
)

버전 없는 명령이 비활성화되어 있으면 qt6_generate_foreign_qml_types() 을 대신 사용합니다. 이 명령과 동일한 인수 집합을 지원합니다.

설명

qt_generate_foreign_qml_typessource_target 에서 QML 등록 매크로(예: QML_ELEMENT)를 통해 표시된 유형을 추출하여 QML 모듈 destination_qml_target 에 외부 유형으로 등록합니다.

이 기능은 QML에 직접 의존하지 않고 선택적 QML 통합을 통해 라이브러리를 만들 때 유용할 수 있습니다.

// myclass.h
#include <QtQmlIntegration/qqmlintegration.h>

class MyClass : public QObject
{
    QML_ELEMENT
    Q_OBJECT

    // [...]
};
# CMakeLists.txt
qt_add_library(mylib myclass.h ...)
target_link_libraries(mylib PRIVATE Qt::Core Qt::QmlIntegration)

qt_add_qml_module(mylib_declarative
  VERSION 1.0
  URI "mylib"
  ...
)
qt_generate_foreign_qml_types(mylib mylib_declarative)

참고: 위의 예에서 mylibQtQml 또는 QtQuick 에 의존하지 않고 헤더 전용 QmlIntegration 대상( QML_ELEMENT 매크로를 제공하는 QtQmlIntegration/qqmlintegration.h 헤더의 경우)에만 의존합니다.

이 효과는 QML 라이브러리에서 사용자 지정 구조체와 함께 QML_FOREIGN 을 사용하여 유형을 노출하는 것과 동일합니다.

참고: 자체 라이프사이클이 있는 기존 싱글톤 인스턴스를 QML에 노출하는 것과 같은 사용자 정의 동작을 구현하려면 QML 라이브러리에 사용자 정의 유형을 추가해야 합니다(위 예제에서는 mylib_declarative). 그리고 원래 C++ 클래스에서 QML_ELEMENT 및 이와 유사한 매크로를 생략하여 qt_generate_foreign_qml_types()가 더 많은 QML 통합 구조체를 생성하지 않도록 해야 합니다. QML 매크로와 모든 싱글톤 팩토리 함수는 QML_FOREIGN 을 포함하는 구조체에 추가할 수 있습니다.

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