【Qt6】VS中 CMakeList 编译报错问题处理

1、 QT_DIR找不到或者Qt6_DIR找不到 

1> [CMake] C:/Users/Administrator/Desktop/test/Table
1> [CMake] CMake Error at C:\Users\Administrator\Desktop\test\Table\CMakeLists.txt:15 (find_package):
1> [CMake]   Could not find a package configuration file provided by "QT" with any of
1> [CMake]   the following names:
1> [CMake] 
1> [CMake]     Qt6Config.cmake
1> [CMake]     qt6-config.cmake
1> [CMake]     Qt5Config.cmake
1> [CMake]     qt5-config.cmake
1> [CMake] 
1> [CMake]   Add the installation prefix of "QT" to CMAKE_PREFIX_PATH or set "QT_DIR" to
1> [CMake]   a directory containing one of the above files.  If "QT" provides a separate
1> [CMake]   development package or SDK, be sure it has been installed.
1> [CMake] 
1> [CMake] 
1> [CMake] -- Configuring incomplete, errors occurred!

解决方式:项目->CMake设置->给QT_DIR设置路径

 注意:如果不知道路径在哪,可以使用everything搜索Qt6Config.cmake

everything下载地址

2、Qt6CoreTools/Qt6GuiTools找不到

1> [CMake] CMake Warning at F:/VS2019IDE/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/CMakeFindDependencyMacro.cmake:47 (find_package):
1> [CMake]   By not providing "FindQt6CoreTools.cmake" in CMAKE_MODULE_PATH this project
1> [CMake]   has asked CMake to find a package configuration file provided by
1> [CMake]   "Qt6CoreTools", but CMake did not find one.
1> [CMake] 
1> [CMake]   Could not find a package configuration file provided by "Qt6CoreTools"
1> [CMake]   (requested version 6.5.3) with any of the following names:
1> [CMake] 
1> [CMake]     Qt6CoreToolsConfig.cmake
1> [CMake]     qt6coretools-config.cmake
1> [CMake] 
1> [CMake]   Add the installation prefix of "Qt6CoreTools" to CMAKE_PREFIX_PATH or set
1> [CMake]   "Qt6CoreTools_DIR" to a directory containing one of the above files.  If
1> [CMake]   "Qt6CoreTools" provides a separate development package or SDK, be sure it
1> [CMake]   has been installed.
1> [CMake] Call Stack (most recent call first):
1> [CMake]   F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6WidgetsTools/Qt6WidgetsToolsDependencies.cmake:9 (find_dependency)
1> [CMake]   F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6WidgetsTools/Qt6WidgetsToolsConfig.cmake:33 (include)
1> [CMake]   F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6/QtPublicDependencyHelpers.cmake:65 (find_package)
1> [CMake]   F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6Widgets/Qt6WidgetsDependencies.cmake:34 (_qt_internal_find_tool_dependencies)
1> [CMake]   F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake:40 (include)
1> [CMake]   F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6/Qt6Config.cmake:157 (find_package)
1> [CMake]   CMakeLists.txt:16 (find_package)
1> [CMake] CMake Warning at F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6/QtPublicDependencyHelpers.cmake:65 (find_package):
1> [CMake]   Found package configuration file:
1> [CMake] 
1> [CMake]     F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6WidgetsTools/Qt6WidgetsToolsConfig.cmake
1> [CMake] 
1> [CMake]   but it set Qt6WidgetsTools_FOUND to FALSE so package "Qt6WidgetsTools" is
1> [CMake]   considered to be NOT FOUND.  Reason given by package:
1> [CMake] 
1> [CMake]   Qt6WidgetsTools could not be found because dependency Qt6CoreTools could
1> [CMake]   not be found.
1> [CMake] 
1> [CMake] Call Stack (most recent call first):
1> [CMake]   F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6Widgets/Qt6WidgetsDependencies.cmake:34 (_qt_internal_find_tool_dependencies)
1> [CMake]   F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake:40 (include)
1> [CMake]   F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6/Qt6Config.cmake:157 (find_package)
1> [CMake]   CMakeLists.txt:16 (find_package)
1> [CMake] CMake Warning at F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6/Qt6Config.cmake:157 (find_package):
1> [CMake]   Found package configuration file:
1> [CMake] 
1> [CMake]     F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake
1> [CMake] 
1> [CMake]   but it set Qt6Widgets_FOUND to FALSE so package "Qt6Widgets" is considered
1> [CMake]   to be NOT FOUND.  Reason given by package:
1> [CMake] 
1> [CMake]   Qt6Widgets could not be found because dependency Qt6WidgetsTools could not
1> [CMake]   be found.
1> [CMake] 
1> [CMake]   Configuring with -DCMAKE_FIND_DEBUG_MODE=TRUE might reveal details why the
1> [CMake]   package was not found.
1> [CMake] 
1> [CMake]   Configuring with -DQT_DEBUG_FIND_PACKAGE=ON will print the values of some
1> [CMake]   of the path variables that find_package uses to try and find the package.
1> [CMake] 
1> [CMake] Call Stack (most recent call first):
1> [CMake]   CMakeLists.txt:16 (find_package)
1> [CMake] CMake Error at C:\Users\Administrator\Desktop\test\Table\CMakeLists.txt:16 (find_package):
1> [CMake]   Found package configuration file:
1> [CMake] 
1> [CMake]     F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6/Qt6Config.cmake
1> [CMake] 
1> [CMake]   but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT
1> [CMake]   FOUND.  Reason given by package:
1> [CMake] 
1> [CMake]   Failed to find required Qt component "Widgets".
1> [CMake] 
1> [CMake]   Expected Config file at
1> [CMake]   "F:/Qt6/6.5.3/msvc2019_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake"
1> [CMake]   exists
1> [CMake] 
1> [CMake]   
1> [CMake] 
1> [CMake]   Configuring with -DCMAKE_FIND_DEBUG_MODE=TRUE might reveal details why the
1> [CMake]   package was not found.
1> [CMake] 
1> [CMake]   Configuring with -DQT_DEBUG_FIND_PACKAGE=ON will print the values of some
1> [CMake]   of the path variables that find_package uses to try and find the package.
1> [CMake] 
1> [CMake] 
1> [CMake] 
1> [CMake] -- Configuring incomplete, errors occurred!

 

操作方式和上面一致。

  • 7
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用和引用的信息,您在使用_vs2022_和_Qt_编译时遇到了关于_BSTR_的编译错误。错误信息是_"C2440: “默认参数”: 无法从“const wchar_t ”转换为“BSTR”_。从代码可以看出,在测试函数_testString_,您尝试将_c_str()_方法返回的_const char *_指针和_bstr_t_对象传递给_testString_函数,但类型不匹配导致编译错误。 要解决这个问题,您可以将_const char *_字符串转换为_BSTR_类型,以便在调用_testString_函数时传递正确的参数类型。您可以使用_::SysAllocString_函数将_const char *_转换为_BSTR_。示例代码如下: ```cpp void testString(const char* str1, const char* str2) { BSTR bstr1 = ::SysAllocString((const OLECHAR*)str1); BSTR bstr2 = ::SysAllocString((const OLECHAR*)str2); // 其他代码... } int main(int argc, char* argv[]) { unsigned char pSrc[] = { 0xE6, 0x88, 0x91, 0xE5, 0x90 , 0x83 , 0xE8 , 0xA5 , 0xBF , 0xE7 , 0xBA , 0xA2 , 0xE6 , 0x9F , 0xBF, 0x00 }; string str1 = (char*)pSrc; _bstr_t str2 = (char*)pSrc; testString(str1.c_str(), (const char*)str2); return 0; } ``` 另外,根据引用的信息,您还可以尝试在_qmake_文件的_Win32_平台下添加以下编译选项来解决_BSTR_编译错误: ```bash win32: QMAKE_CXXFLAGS_RELEASE -= -Zc:strictStrings win32: QMAKE_CFLAGS_RELEASE -= -Zc:strictStrings win32: QMAKE_CFLAGS -= -Zc:strictStrings win32: QMAKE_CXXFLAGS -= -Zc:strictStrings ``` 这些编译选项将移除严格字符串检查,可能有助于解决编译错误。 请注意,以上提供的解决方案仅供参考,请根据您的具体情况进行调整和验证。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [VS + QT windows工程重新构建遇到的问题](https://blog.csdn.net/qq_34062754/article/details/109487424)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [_bstr_t 使用出现错误](https://blog.csdn.net/u012607841/article/details/19688901)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值