Skip to content

JayTwoLab/vscode-cmake-qt-mingw-exe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vscode-cmake-qt-mingw-exe

This is a template project for developing a console application using CMake, Qt6, and MinGW with Visual Studio Code.

Project Overview

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.

Key Features

  • 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

Development Environment Requirements

  • 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

Required VS Code Extensions

  • CMake Tools
  • C/C++ Extension Pack

Installation and Setup

1. Install Qt and MinGW

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.

2. Clone the Project

git clone https://github.com/JayTwoLab/vscode-cmake-qt-mingw-exe.git
cd vscode-cmake-qt-mingw-exe

3. Open the Project in VS Code

code .

Build Instructions

Using CMake Presets

The project provides two build presets:

Debug Build

cmake --preset mingw-debug
cmake --build --preset mingw-debug

Release Build

cmake --preset mingw-release
cmake --build --preset mingw-release

Building in VS Code

  1. Press Ctrl+Shift+P to open the Command Palette
  2. Select "CMake: Select Configure Preset"
  3. Choose "MinGW Debug" or "MinGW Release"
  4. Build using F7 or the "CMake: Build" command

Running the Application

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.

Project Structure

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

Key CMake Configuration Details

  • C++ Standard: C++17
  • Automatic MOC/UIC/RCC: Qt meta-object compiler features enabled automatically
  • Debug Optimization: Forces -g -O0 flags for Windows MinGW Debug builds
  • Automatic Qt Path Setup: Automatically configures Qt paths for Windows MinGW environments

Code Example

#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;
}

Customization

Adding Qt Modules

find_package(Qt6 REQUIRED COMPONENTS Core Widgets Network)

target_link_libraries(${PROJECT_NAME} PRIVATE
    Qt6::Core
    Qt6::Widgets
    Qt6::Network
)

Adding Source Files

add_executable(${PROJECT_NAME}
    main.cpp
    myclass.cpp
    myclass.h
)

License

This project is distributed under the MIT License. See the LICENSE file for details.

Contributing

Issues and pull requests are welcome.

Related Links

Troubleshooting

Qt Not Found

Update the CMAKE_PREFIX_PATH in the CMakePresets.json file.

MinGW Compiler Not Found

Verify the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER paths.

Debugging Does Not Work

Check the program path in .vscode/launch.json.

About

Template project for CMake, Ninja, Qt6, MinGW, VSCode.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors