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는 Quick이 의존하는 패키지(예: Qt6Qml)도 자동으로 로드하며, 이 패키지에는 아래에서 사용할 qt_add_qml_module() 명령어가 정의되어 있습니다.

또한 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::Quick 이 의존하는 타깃( Qt6::Qml 및 Qt6::Core 포함)에 대해서도 자동으로 링크됩니다.

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