I have full working project for QtCreator and I try to run it in VSCode. There is configuration inside the project the c_cpp_properties.json with following include paths:
"includePath": [
"${workspaceFolder}/**",
"C:\Qt_v2\6.7.0\msvc2019_64\include\QtCore\**"
],
but this doesn’t lead to success, there are still many errors.
Typical errors inside project header files “qobject.h(10, 10): ‘QtCore/qobjectdefs.h’ file not found” or inside the deep library code “this declaration has no storage class or type specifierC/C++(77), QT_BEGIN_NAMESPACE” and a lot of other errors.”
Part of CMakeList.txt
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
find_package(Qt6 6.5 REQUIRED COMPONENTS
Core
Charts
Sql
Quick
SerialBus
Scxml
Test
Xml
LinguistTools
Widgets
)
qt_standard_project_setup(REQUIRES 6.5)
# Link the Qt modules
target_link_libraries(app-name PRIVATE
Qt6::Quick
Qt6::Sql
Qt6::Xml
Qt6::Scxml
Qt6::Core
Qt6::Widgets
)
target_link_libraries(app-name LINK_PUBLIC
App
GUIplugin
)
It looks like I have included wrong path or something else. There is no good explanation on internet to read what to configure in VSCode to be able to code with Qt 6.7 in VSCode (I have installed QtCreator).
The final expectation are to have the code without errors inside Qt includes, to have auto complete and be able to build the code.
1
I use this KDAB Doc and its GitHub Repo In Windows 11.
you need to add an environment variable that points to Qt (like C:Qt6.5.3mingw_64bin
) in the Windows Environment available path.
This is its Cmake file
cmake_minimum_required(VERSION 3.5)
project(test_qtinVsCode VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
set(PROJECT_SOURCES
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(test_qtinVsCode
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET test_qtinVsCode APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(test_qtinVsCode SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(test_qtinVsCode
${PROJECT_SOURCES}
)
endif()
endif()
target_link_libraries(test_qtinVsCode PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.test_qtinVsCode)
endif()
set_target_properties(test_qtinVsCode PROPERTIES
${BUNDLE_ID_OPTION}
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
include(GNUInstallDirs)
install(TARGETS test_qtinVsCode
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(test_qtinVsCode)
endif()