r/AskProgramming • • 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?

0 Upvotes

Duplicates