インポートターゲット

ロードされる各Qtモジュールは、CMakeライブラリターゲットを定義します。ターゲット名はQt6:: で始まり、その後にモジュール名が続きます。例えばQt6::Core Qt6::Gui 。各ライブラリを使用するには、ライブラリターゲットの名前をtarget_link_libraries に渡します。

注意: ターゲットには、Qt:: というプレフィックスを付けることもできます:Qt::Core Qt::Gui など。Qt 5 と Qt 6 の互換性も参照してください。

インポートされたターゲットは、Qt が設定されたときと同じ設定で作成されます。つまり

  • Qt が-debug スイッチで構成されていた場合、DEBUG 構成のインポートターゲットが作成されます。
  • Qt が-release スイッチで構成されていた場合、RELEASE 構成のインポートターゲットが作成されます。
  • Qt が-debug-and-release スイッチで構成されている場合、RELEASE と DEBUG の両方の構成でインポートされたターゲットが作成されます。

プロジェクトにCMake のカスタムビルド構成がある場合は、カスタム構成をデバッグまたはリリースの Qt 構成にマッピングする必要があります。

find_package(Qt6 REQUIRED COMPONENTS Core)

set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage")

# set up a mapping so that the Release configuration for the Qt imported target is
# used in the COVERAGE CMake configuration.
set_target_properties(Qt6::Core PROPERTIES MAP_IMPORTED_CONFIG_COVERAGE "RELEASE")

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