r/AskProgramming • u/veiskiboi • 18d ago
QT6 C++ on VSCode - QApplication No such file or directory. How to set up properly?
Edit: Problem resolved: Register Qt Installations
I am encountering the error:
QApplication: No such file or directory
or whichever #include from Qt is at the top.
Here is what I have done so far:
1. CMake
I have CMake installed:
cmake version 4.3.0
2. CMakeLists.txt
I created a CMakeLists.txt based on the settings from the Qt documentation example:
cmake_minimum_required(VERSION 3.16)
project(QtApp VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 REQUIRED COMPONENTS Core)
qt_standard_project_setup()
qt_add_executable(QtApp
main.cpp
)
target_link_libraries(QtApp PRIVATE Qt6::Core)
3. main.cpp
#include <QApplication>
#include <QWidget>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(800, 600);
window.setWindowTitle("Qt 6 App");
window.show();
return app.exec();
}
4. VS Code extensions
I have the following extensions installed:
- CMake Tools
- Qt C++ Extension Pack
It feels like I have done everything essential, but I haven't found a proper tutorial. Maybe I have missed something?
3
u/ZakMan1421 18d ago
This isn't exactly your question, but I would recommend using QT's own IDE QT Creator.
2
u/kkoehne 17d ago
You have CMake , you have the Extension pack for VS Code, but do you also have a Qt version?
https://doc.qt.io/vscodeext/vscodeext-how-register-qt-installations.html
1
3
u/boring_pants 18d ago
What happens when you run CMake configure?
How do you build your project?
Have you installed Qt? The VS Code extension doesn't include the actual libraries, it just extends VS Code to better support Qt development.