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
- C++ core: Handles logic, algorithms, file I/O, networking, etc.
- GUI library/framework: Handles windows, buttons, menus, text boxes, images, etc.
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)
- Win32 API (Windows): You can directly call Windows API functions to create and manage windows, buttons, etc. This is verbose but works without extra frameworks.
- Cocoa (macOS): Can be accessed from C++ with Objective-C++.
- Xlib/XCB (Linux/X11): Very low-level; usually wrapped by higher-level toolkits.
Step-by-Step Workflow for Writing a C++ Desktop App
- Pick your toolkit (e.g., Qt).
- Write your GUI code using toolkit classes (QMainWindow, QPushButton, etc.).
- Write your application logic in C++.
- Compile and link against the toolkit's libraries.
- 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
- Performance — close to the metal.
- Control — fine-grained tuning possible.
- Cross-platform — with the right toolkit.
- Integration — easy to combine with game engines, device drivers, embedded systems.
Building an Actual Project (on Windows using Visual Studio Code)
Install the required tools
- C++ Compiler & Build Tools
There are two good options
Option A – MSVC (Microsoft Visual C++ toolchain)
- Download Visual Studio Community.
- During install, tick "Desktop development with C++".
- This installs cl.exe, MSBuild, and the Windows SDK.
Option B - MinGW-w64 via MSYS2
- Download MSYS2.
- Run MSYS2 and install:
pacman -Syu
pacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-cmake
- 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.
-
Install Qt 6
- Download the Qt Online Installer from https://www.qt.io/download-open-source.
- When prompted, log in or create a Qt account.
- In the component selection:
- Select Qt 6.x.x → MSVC 64-bit.
- Optional: Qt Creator IDE (you’ll use VS Code, so optional).
- Install to something like:
makefile
C:\Qt\6.7.2\msvc2019_64
(The path will vary by Qt version.)
-
Install CMake
- Download from https://cmake.org/download/ (Windows x64 installer).
- During install, tick “Add CMake to system PATH for all users”.
-
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
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.
Configure the Build in VS Code
- Open myapp in VS Code.
- At the bottom bar (CMake Tools), select a kit:
- Click [No active kit] → choose Visual Studio 17 2022 Release - amd64 (or your MSVC version).
- Click the gear icon (Configure Project) — CMake will find Qt using the CMAKE_PREFIX_PATH in your CMakeLists.txt.
- Click Build (or press F7).
Run the App
- After building, VS Code shows a ▶ button at the bottom bar for Run.
- The Qt window should appear with a Hello, world! button.
- Click the button → message appears in VS Code's Debug Console:
Button was clicked!
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.
Tips for Smooth Development
- Keep Qt path changes in CMakeLists.txt or set CMAKE_PREFIX_PATH globally in CMake Tools settings.
- Use Layouts (QVBoxLayout, QHBoxLayout) instead of manual widget sizes for resizable UIs.
- VS Code’s debugger works fine — set breakpoints, step through, inspect variables.
At this point you have:
- Qt installed on Windows.
- A working C++/Qt GUI project in VS Code.
- Build, run, and deploy workflow.
C++ Core vs. GUI
Para 2.
Code Sample
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