问题描述
Visual Studio代码出现以下错误:
Visual Studio Code gets the following error:
cannot open source file "QtWidgets/qtwidgetsglobal.h" (dependency of "QApplication")C/C++(1696)
我有一个成功编译和构建的CMake项目,但是Intellisense似乎不起作用.
I have a CMake project which compiled and built successfully, but it seems that Intellisense doesn't work.
我在包含 qtwidgetsglobal.h
的路径中有此目录:
I have this directory in a path which contains qtwidgetsglobal.h
:
/usr/local/Cellar/qt/5.13.1/lib/QtWidgets.framework/Headers
还有另一件事:
目录/usr/local/Cellar/qt/5.13.1/lib/QtWidgets.framework
包含目录 Headers
和奇怪的可执行文件 QtWidgets
,我假设其中包含 -I/usr/local/Cellar/qt/5.13.1/lib/QtWidgets.framework
,因为QtCreator兼有/usr/local/Cellar/qt/5.13.1/lib/QtWidgets.framework
和/usr/local/Cellar/qt/5.13.1/lib/QtWidgets.framework/Headers
但没有任何效果.
Directory /usr/local/Cellar/qt/5.13.1/lib/QtWidgets.framework
contains directory Headers
and strange executable QtWidgets
I was assumed to include -I/usr/local/Cellar/qt/5.13.1/lib/QtWidgets.framework
because QtCreator has both/usr/local/Cellar/qt/5.13.1/lib/QtWidgets.framework
and/usr/local/Cellar/qt/5.13.1/lib/QtWidgets.framework/Headers
but nothing worked.
实际上,如果两个目录都被Visual Studio Code忽略,/usr/local/Cellar/qt/5.13.1/lib/QtWidgets.framework
和/usr/local/Cellar/qt/5.13.1/lib/QtWidgets.framework/Headers
指定.
Actually Visual Studio Code seems to ignore if both directories/usr/local/Cellar/qt/5.13.1/lib/QtWidgets.framework
and/usr/local/Cellar/qt/5.13.1/lib/QtWidgets.framework/Headers
specified.
关于如何使Intellisense与Visual Studio Code一起使用的任何建议.
Any suggestions how to enable Intellisense to work with Visual Studio Code.
推荐答案
您需要使用compileCommands而不是cake-tools configurationProvider.
You need to use the compileCommands instead of the cake-tools configurationProvider.
因此在您的 c_cpp_properties.json
中添加该行
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
然后删除
"configurationProvider": "ms-vscode.cmake-tools",
完整的配置文件应如下所示
The full config file should look something like this
{
"configurations": [
{
"name": "Mac",
"compilerPath": "/usr/bin/clang",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"browse": {
"limitSymbolsToIncludedHeaders": true
},
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"cStandard": "c11",
"intelliSenseMode": "clang-x64",
"cppStandard": "c++14"
}
],
"version": 4
}
这篇关于macOS + Qt + Intellisense上的Visual Studio代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!