如果你想使用Clion开发Qt软件
如果你想在Windows上使用Clion开发Qt
如果你还想使用MSVC编译器开发Qt
但是却遇到了各种各种编译报错,那么恭喜你这些坑都有人帮你踩过了
CMake Error at CMakeLists.txt:25 (find_package):
Could not find a package configuration file provided by "QT" with any of
the following names:
Qt6Config.cmake
qt6-config.cmake
Qt5Config.cmake
qt5-config.cmake
Add the installation prefix of "QT" to CMAKE_PREFIX_PATH or set "QT_DIR" to
a directory containing one of the above files. If "QT" provides a separate
development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
[无法重新加载]
是因为没有在Cmake中配置CMAKE_PREFIX_PATH,在CmakeLists中加上:
set(CMAKE_PREFIX_PATH "C:/App/Qt/Qt6/6.4.3/msvc2019_64")
#请在导入Qt相关依赖包之前,配置CMAKE_PREFIX_PATH,这里的路径填写自己电脑上的qt-msvc路径
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core )
CMake Error at CMakeLists.txt:25 (find_package):
Could not find a configuration file for package "QT" that is compatible
with requested version "".
The following configuration files were considered but not accepted:
C:/App/Qt/Qt6/6.4.3/msvc2019_64/lib/cmake/Qt6/Qt6Config.cmake, version: 6.4.3 (64bit)
-- Configuring incomplete, errors occurred!
你发现配置了CMAKE_PREFIX_PATH 还是报错,特别是msvc下报错,那么你需要在Cmake工具链配置中修改:
工具链:你选择的对应编译器
生成器:一般msvc选择让cmake决定
之后重新构建cmake,只有cmake的缓存变量中识别到了QT环境,才能编译通过~
后续待补充~