在 Qt 上使用 CMake 配置 VSCode - 找不到 ui_*.h 文件

Configuring VSCode with CMake on Qt - ui_*.h files can't be found

本文关键字:ui 找不到 文件 VSCode Qt 配置 CMake      更新时间:2023-10-16

我正在尝试使用Microsoft C/C IntelliSense扩展名配置VSCODE以使用C 和QT进行的项目运行。

某些文件包括QT UI标题,格式:

#include "ui_filename.h"

然而,这些是用红色的痕迹和消息强调的:

#include errors detected. Consider updating your compile_commands.json or includePath. Squiggles are disabled for this translation unit (/path/to/my/workspace).
cannot open source file "ui_filename.h"

这些文件位于目录build.debug/中,该目录是我的根工作区目录的子目录。

我尝试使用CMAKE工具扩展名,仅使用以下方式进行配置:

"cmake.copyCompileCommands": "build/compile_commands.json"

build是项目目录,用于与构建有关的所有事情。

C/C 扩展的配置具有以下相关行:

        "includePath": [
            "${workspaceFolder}/**",
            "/usr/include/x86_64-linux-gnu/qt5/**"
        ],
        ...
        "compileCommands": "${workspaceFolder}/build/compile_commands.json"

但是,这仍然无法解决问题。我还尝试过安装CMAKE工具助手扩展程序,具有讽刺意味的是无济于事。

我不确定从这里去哪里。其他一切正常,QT定义都已识别,并且所有正常的标题都识别出来。我已经检查过,并且我的工作区中肯定存在UI标头文件。我能做些什么?非常感谢帮助。

看来,您似乎必须手动将文件路径添加到项目包含路径中。在此处查看手册部分以获取更多信息。