Software

←Index

C++ The Basics

by Professor Petabyte

 

Does C++ have a front-end or GUI?
          How are desktop apps written with C++?

C++ itself does not come with a built-in front-end or GUI toolkit — it's just a general-purpose programming language. If you want a graphical desktop application, you need to use external libraries or frameworks that provide GUI capabilities.

Here's how it works:

C++ Core vs. GUI

The standard C++ library only includes console I/O (std::cout, std::cin) - nothing for making windows.

Popular C++ GUI Frameworks

Framework Notes Platforms
QT Modern, feature-rich, open-source (LGPL) or commercial; has designer tools; widely used in industry Windows, macOS, Linux
wxWidgets Native look & feel by wrapping OS APIs Windows, macOS, Linux
GTKmm C++ bindings for GTK (GNOME toolkit) Windows, macOS, Linux
FLTK Lightweight, fast; minimal dependencies Windows, macOS, Linux
ImGui Immediate-mode GUI, often for tools/debugging in games Cross-platform
MFC (Microsoft Foundation Classes) Old but still in use for legacy Windows apps Windows only

Native APIs (no external library)

Step-by-Step Workflow for Writing a C++ Desktop App

  1. Pick your toolkit (e.g., Qt).
  2. Write your GUI code using toolkit classes (QMainWindow, QPushButton, etc.).
  3. Write your application logic in C++.
  4. Compile and link against the toolkit's libraries.
  5. Distribute the executable with the needed libraries.

Example (Qt minimal program):

#include 
#include 

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

    QPushButton button("Hello, World!");
    button.show();

    return app.exec();
}

Why do People Still Use C++ for GUI Apps

Building an Actual Project (on Windows using Visual Studio Code)

  1. Install the required tools

    1. C++ Compiler & Build Tools

      There are two good options

      Option A – MSVC (Microsoft Visual C++ toolchain)
      1. Download Visual Studio Community.
      2. During install, tick "Desktop development with C++".
      3. This installs cl.exe, MSBuild, and the Windows SDK.
      Option B - MinGW-w64 via MSYS2
      1. Download MSYS2.
      2. Run MSYS2 and install:
        pacman -Syu
        pacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-cmake
      3. Use the "MSYS2 MinGW UCRT64" terminal when building.

      Most Qt tutorials use MSVC for Windows; it's better for Qt Creator integration, so use of MSVC will be assumed here.

    2. Install Qt 6

      1. Download the Qt Online Installer from https://www.qt.io/download-open-source.
      2. When prompted, log in or create a Qt account.
      3. In the component selection:
        • Select Qt 6.x.x → MSVC 64-bit.
        • Optional: Qt Creator IDE (you’ll use VS Code, so optional).
      4. Install to something like:

        makefile

        C:\Qt\6.7.2\msvc2019_64

        (The path will vary by Qt version.)

    3. Install CMake

      1. Download from https://cmake.org/download/ (Windows x64 installer).
      2. During install, tick “Add CMake to system PATH for all users”.
    4. Install VS Code Extensions

      In VS Code, press Ctrl+Shift+X and install:

      • CMake Tools (ms-vscode.cmake-tools)
      • C/C++ (ms-vscode.cpptools)
      • CMake (twxs.cmake) — optional syntax highlighting
  2. Create the Project Structure

    Make a folder myapp:

    myapp/
      src/
        main.cpp
      CMakeLists.txt
    src/main.cpp
    #include 
    #include 
    #include 
    
    int main(int argc, char *argv[]) {
        QApplication app(argc, argv);
    
        QPushButton button("Hello, world!");
        button.resize(220, 60);
    
        QObject::connect(&button, &QPushButton::clicked, [](){
            qDebug() << "Button was clicked!";
        });
    
        button.show();
        return app.exec(); // Event loop
    }
    

    CMakeLists.txt

    cmake_minimum_required(VERSION 3.16)
    project(MyQtApp LANGUAGES CXX)
    
    set(CMAKE_CXX_STANDARD 17)
    
    # Tell CMake where to find Qt
    set(CMAKE_PREFIX_PATH "C:/Qt/6.7.2/msvc2019_64/lib/cmake")
    
    find_package(Qt6 COMPONENTS Widgets REQUIRED)
    
    add_executable(myqtapp src/main.cpp)
    target_link_libraries(myqtapp PRIVATE Qt6::Widgets)
    Replace C:/Qt/6.7.2/msvc2019_64/lib/cmake with the actual Qt path on your PC.

  3. Configure the Build in VS Code

  4. Run the App

  5. Deployment (Windows)

    By default, your .exe won't run on another PC without Qt DLLs.

    Use windeployqt (included with Qt) to bundle dependencies:

    From the build folder:
    powershell

    & "C:\Qt\6.7.2\msvc2019_64\bin\windeployqt.exe" .\Debug\myqtapp.exe

    for for Release:
    powershell

    & "C:\Qt\6.7.2\msvc2019_64\bin\windeployqt.exe" .\Release\myqtapp.exe

    It will copy all needed DLLs and plugins into the same folder as the EXE.

  6. Tips for Smooth Development

At this point you have:

C++ Core vs. GUI

Para 2.

Code Sample
Zoomable Image
Mouseover to Zoom
Column names go here
Column content goes here
Column content goes here
Column content goes here
Column content goes here

Bullet list preamble

Numbered list preamble




© 2025 Professor Petabyte