我想为我的项目使用 QtQuickCompiler,但是一旦我调用 qtquick_compiler_add_resources,我就会收到以下错误消息:
Unknown CMake command "qtquick_compiler_add_resources".
我使用 Qt6 和 CMake 3.18.2。我已经阅读了很多文档,但是这里的所有内容都应该是正确的。那是我的 CMakeLists.txt:
cmake_minimum_required(VERSION 3.14)
project(ProtoPaste LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_PREFIX_PATH "C:/Qt/6.0.0/msvc2019_64/lib/cmake")
set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_CURRENT_SOURCE_DIR}/src/Resource.rc")
option(CLIP_TESTS OFF)
option(CLIP_EXAMPLES OFF)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick QuickControls2 Widgets Qt6QuickCompiler REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick QuickControls2 Widgets REQUIRED)
qtquick_compiler_add_resources(RESOURCES
src/qml.qrc
src/images.qrc
)
set(PROJECT_SOURCES
src/main.cpp
src/availableElement.cpp
src/selectedElement.cpp
src/availableElementsModel.cpp
src/selectedElementsModel.cpp
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(ProtoPaste WIN32
${PROJECT_SOURCES}
${RESOURCES}
${APP_ICON_RESOURCE_WINDOWS}
)
else()
add_executable(ProtoPaste WIN32
${PROJECT_SOURCES}
${RESOURCES}
${APP_ICON_RESOURCE_WINDOWS}
)
endif()
add_subdirectory(dependencies)
target_include_directories(ProtoPaste PRIVATE ${clip_SOURCE_DIR})
target_compile_definitions(ProtoPaste PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(ProtoPaste
PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick Qt${QT_VERSION_MAJOR}::QuickControls2 Qt${QT_VERSION_MAJOR}::Widgets clip)
我究竟做错了什么?