This is a template project for developing a console application using CMake, Qt6, and MinGW with Visual Studio Code.
This project demonstrates how to build a Qt6-based console application using the MinGW compiler on Windows. Visual Studio Code is used as the IDE, and CMake is used as the build system.
- Qt6 Core Integration: Basic console application using the Qt6 Core library
- CMake Build System: Modern CMake configuration (CMake 3.26 or later)
- CMakePresets Support: Provides Debug and Release build presets
- MinGW Compiler: Uses MinGW GCC compiler on Windows
- VS Code Integration: Includes a complete VS Code development environment configuration
- CMake: 3.26 or later
- Qt: 6.9.2 (MinGW 64-bit version)
- MinGW: GCC 13.1.0 (included in Qt Tools)
- Ninja: Build generator
- Visual Studio Code: With recommended extensions
- CMake Tools
- C/C++ Extension Pack
Install Qt 6.9.2 and MinGW to the following paths:
C:/Qt/6.9.2/mingw_64
C:/Qt/Tools/mingw1310_64
If you install them in different locations, you must update the paths in the CMakePresets.json file.
git clone https://github.com/JayTwoLab/vscode-cmake-qt-mingw-exe.git
cd vscode-cmake-qt-mingw-execode .The project provides two build presets:
cmake --preset mingw-debug
cmake --build --preset mingw-debugcmake --preset mingw-release
cmake --build --preset mingw-release- Press
Ctrl+Shift+Pto open the Command Palette - Select "CMake: Select Configure Preset"
- Choose "MinGW Debug" or "MinGW Release"
- Build using
F7or the "CMake: Build" command
After building, the executable is generated at the following locations:
- Debug:
build/debug/qt_console_hello.exe - Release:
build/release/qt_console_hello.exe
You can run the application in debug mode by pressing F5 in VS Code.
vscode-cmake-qt-mingw-exe/
├── .vscode/ # VS Code configuration files
│ ├── c_cpp_properties.json
│ ├── extensions.json
│ ├── launch.json
│ ├── settings.json
│ └── tasks.json
├── CMakeLists.txt # CMake build configuration
├── CMakePresets.json # CMake preset configuration
├── main.cpp # Main source file
├── LICENSE # License file
└── README.md # Project documentation
- C++ Standard: C++17
- Automatic MOC/UIC/RCC: Qt meta-object compiler features enabled automatically
- Debug Optimization: Forces
-g -O0flags for Windows MinGW Debug builds - Automatic Qt Path Setup: Automatically configures Qt paths for Windows MinGW environments
#include <iostream>
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::cout << std::endl << "Hello, World!" << std::endl << std::endl;
std::cout << "more ..." << std::endl;
std::cout << "more 2 ..." << std::endl;
return 0;
}find_package(Qt6 REQUIRED COMPONENTS Core Widgets Network)
target_link_libraries(${PROJECT_NAME} PRIVATE
Qt6::Core
Qt6::Widgets
Qt6::Network
)add_executable(${PROJECT_NAME}
main.cpp
myclass.cpp
myclass.h
)This project is distributed under the MIT License. See the LICENSE file for details.
Issues and pull requests are welcome.
Update the CMAKE_PREFIX_PATH in the CMakePresets.json file.
Verify the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER paths.
Check the program path in .vscode/launch.json.