이 페이지에서

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_types source_target 에서 QML 등록 매크로( 등)를 통해 표시된 타입을 추출하여, QML 모듈 에 외부 타입으로 등록합니다. QML_ELEMENT 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)

참고: 위의예에서 mylib 는 QtQml 나 QtQuick 에 의존하지 않고, 헤더 전용 QmlIntegration 타깃( QML_ELEMENT 매크로를 제공하는 qqmlintegration.h 헤더용)에만 의존합니다.

이 효과는 QML 라이브러리에서 사용자 정의 구조체(struct)를 사용하여 유형을 노출할 때 QML_FOREIGN 를 사용하는 것과 동일합니다.

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

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