Open wuxianggujun opened 1 year ago
make sure you setup your Qt major version properly, it's documented
确保你正确设置了你的 Qt 主要版本,它被记录在案
I'm a newbie and I don't know how. This is my Cmakefile file.
cmake_minimum_required(VERSION 3.24) #指定cmake版本
project(QT_ProjectExample) #工程名
set(CMAKE_CXX_STANDARD 20) #使用的C++标准
# 开启QT用于预处理的组件
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
# 设置cmake模块查询目录,注意这里的路径到mingw64既可
set(CMAKE_PREFIX_PATH "D:/msys64/mingw64")
add_subdirectory(include/QXlsx)
include_directories(
${PROJECT_SOURCE_DIR}/include
# ${PROJECT_SOURCE_DIR}/Sources/Forms
${PROJECT_SOURCE_DIR}/Sources/Headers
${PROJECT_SOURCE_DIR}/include/QXlsx
)
# 查找QT模块
find_package(Qt6 COMPONENTS
Core
Gui
Widgets
REQUIRED)
# 引入lib目录的lib文件什么的
link_directories(./lib)
# 添加源文件
add_executable(QT_ProjectExample Sources/main.cpp Sources/mainwindow.cpp Sources/Headers/mainwindow.h Sources/Forms/mainwindow.ui)
# 添加模块
target_link_libraries(QT_ProjectExample
Qt::Core
Qt::Gui
Qt::Widgets
)
target_link_libraries(${PROJECT_NAME} QXlsx)
if (WIN32)
set(DEBUG_SUFFIX)
if (MSVC AND CMAKE_BUILD_TYPE MATCHES "Debug")
set(DEBUG_SUFFIX "d")
endif ()
set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}")
if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
endif ()
endif ()
if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
endif ()
foreach (QT_LIB Core Gui Widgets)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${QT_INSTALL_PATH}/bin/Qt6${QT_LIB}${DEBUG_SUFFIX}.dll"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>")
endforeach (QT_LIB)
endif ()
I've managed to solve it by looking at other open source projects
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui REQUIRED)
Like this
CMake Error: The INTERFACE_QT_MAJOR_VERSION property of "Qt5::Core" does not agree with the value of QT_MAJOR_VERSION already determined for "QT_ProjectExample".