How do I configure Qt6 headers correctly for a C++ project in VS Code?

0
11
Asked By MellowPine47 On

I'm setting up a small Qt 6 C++ application in VS Code on Linux, but VS Code reports errors such as "QApplication: No such file or directory" for Qt includes. I installed CMake 4.3.0, the CMake Tools and Qt C++ extensions, and created a CMake project using the Qt documentation pattern with Qt6::Widgets. CMake configures successfully in a build directory, and I can build with `cmake --build build`. `qmake --version` reports Qt 6.11.2 installed under `/usr/lib64`. My source includes QApplication and QPushButton, but the editor still cannot find the Qt headers. What else should I configure or check?

3 Answers

Answered By QuietMaple31 On

Your CMake file is broadly correct. The Qt VS Code extension is optional and is not a replacement for installing Qt’s development files. If CMake really completes and `cmake --build build` succeeds, the application should compile even if the editor displays “file not found.” If the build also fails, install the Qt 6 Widgets development package for your distribution and rerun CMake after clearing or recreating the build directory.

Answered By CrispHarbor8 On

The VS Code extensions don’t install Qt itself; they only add editor and CMake integration. Make sure the Qt development package and headers are installed, not just the runtime or qmake. Since CMake configures successfully, the remaining problem may only be IntelliSense. Enable compilation database generation with `set(CMAKE_EXPORT_COMPILE_COMMANDS ON)`, reconfigure the project, and point the C/C++ extension at `build/compile_commands.json`, or select the active CMake configure kit. Then reload VS Code.

VelvetOrbit22 -

The Qt installation shown by qmake is a good sign, but the compiler and the editor still need the include paths generated by CMake. Check whether the actual build command succeeds; if it does, the red underline is an IntelliSense configuration issue rather than a C++ or Qt error.

Answered By NimbleCedar6 On

Make sure VS Code is using the same CMake build directory and compiler that you configured from the terminal. Use the CMake Tools commands to select a kit, configure, and build the target. You can also open the generated `compile_commands.json` to verify that it contains Qt include directories such as the Qt installation’s `include` path. Don’t manually add random include directories unless CMake is failing to find Qt.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.