QML 애플리케이션 빌드하기
C++ 콘솔 애플리케이션 빌드에서 간단한 콘솔 애플리케이션을 위한 CMakeLists.txt 파일을 보여드렸습니다. 이제 이 파일에 있는 Qt Quick 모듈을 사용하는 QML 애플리케이션을 만들어 보겠습니다.
다음은 전체 프로젝트 파일입니다:
cmake_minimum_required(VERSION 3.16) project(helloworld VERSION 1.0.0 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 6.5 COMPONENTS Quick REQUIRED) qt_standard_project_setup(REQUIRES 6.5) qt_add_executable(helloworld main.cpp ) qt_add_qml_module(helloworld URI hello QML_FILES main.qml FramedImage.qml RESOURCES img/world.png ) target_link_libraries(helloworld PRIVATE Qt6::Quick)
콘솔 애플리케이션 CMakeLists.txt
과 비교하여 우리가 변경한 사항을 살펴봅시다:
... find_package(Qt6 6.5 COMPONENTS Quick REQUIRED)
find_package()
호출에서 Core
을 Quick
로 바꿉니다. 따라서 CMake는 Qt6Quick
모듈을 로드하고 나중에 링크할 Qt6::Quick
타깃을 제공합니다. 또한 CMake는 아래에서 사용하는 qt_add_qml_module() 명령을 정의하는 Qt6Qml
와 같이 Quick이 의존하는 패키지를 자동으로 로드합니다.
또한 Qt 6.5 이상이 필요합니다.
qt_standard_project_setup(REQUIRES 6.5)
qt_standard_project_setup() 명령은 일반적인 Qt 애플리케이션의 프로젝트 전체 기본값을 설정합니다. REQUIRES 6.5
을 추가하면, qt_add_qml_module()에 의해 생성된 QML 모듈의 기본 리소스 접두사를 정의하는 정책 QTP0001이 활성화됩니다.
... qt_add_qml_module(helloworld URI hello QML_FILES main.qml FramedImage.qml RESOURCES img/world.png )
qt_add_qml_module()은 실행 파일에 hello
이라는 이름의 QML 모듈을 추가하며, 이 모듈은 두 개의 QML 파일과 하나의 이미지로 구성됩니다. QTP0001로 인해 이 모듈은 리소스 파일 시스템의 qrc:/qt/qml/hello
에서 사용할 수 있으며, qrc:/qt/qml/
은 QML 엔진의 기본 임포트 경로 중 하나입니다.
또한qt_add_qml_module()은 QML 스크립트 컴파일러를 실행하고 helloworld_qmllint
대상을 정의하는 등의 최적화 단계를 수행하며, 이를 실행하여 qmllint에서 .qml
파일에 대한 추가 제안을 얻을 수 있습니다.
target_link_libraries(helloworld PRIVATE Qt6::Quick)
target_link_libraries()
명령에서는 실행 파일을 Qt6::Quick
에 대해 링크합니다. 이렇게 하면 Qt6::Qml
및 Qt6::Core
를 포함하여 Qt6::Quick
가 의존하는 타깃에도 자동으로 링크됩니다.
© 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.