Setting Up the Qt Environment

Install Qt Creator, configure Qt 6 with CMake, and set up a cross-compilation toolchain for embedded Linux targets.

15 min read
88927 chars

Introduction & Setup


1. Introduction to Qt

Qt (pronounced “cute”) is a cross-platform application framework written in C++. It provides a comprehensive set of libraries and tools for building: Qt Framework Overview

Qt Ecosystem β€” Module Map

    
%%{init: {
  "theme": "base",
  "themeVariables": {
    "primaryColor":       "#6366f1",
    "primaryTextColor":   "#ffffff",
    "primaryBorderColor": "#4f46e5",
    "lineColor":          "#6366f1",
    "secondaryColor":     "#0ea5e9",
    "tertiaryColor":      "#f0f4ff",
    "backgroundColor":     "#ffffff"
  }
}}%%
mindmap
  root((Qt Framework))
    )🧠 Core(
      Qt Core
      Qt Concurrent
      Qt SQL
      Qt XML
    )🎨 UI(
      Qt Widgets
      Qt Quick
      QML
      Qt WebEngine
    )πŸ”Œ Connectivity(
      Qt Network
      Qt SerialPort
      Qt Bluetooth
      Qt WebSockets
    )πŸ› οΈ Tools(
      Qt Creator IDE
      Qt Designer
      CMake
      Qt Linguist
    )πŸš€ Deployment(
      Windows
      Linux
      macOS
      Android Β· iOS
      Embedded MCU


2. Why Qt?

Key Advantages

FeatureWhat It Means
Write Once, Run AnywhereSame C++ codebase β†’ Windows, Linux, macOS, Android, iOS, Embedded
Signals & SlotsBuilt-in type-safe event system β€” no manual callbacks
Qt Creator IDEIntegrated designer, debugger, profiler, and device deployment
Embedded-FirstUsed in automotive HMI, industrial panels, medical devices
Dual LicenseOpen-source (LGPLv3) + Commercial β€” use freely in most projects
Best-in-class DocsOfficial docs + examples for every class
QML / Qt QuickDeclarative UI language for modern animated interfaces

3. History of Qt

Qt history


4. Setup β€” Step by Step


4.1 Windows

Requirements: Windows 10+ (64-bit) Β· ~10 GB free disk Β· Internet connection

Step 1 β€” Download the Installer

Go to qt.io/download β†’ Open Source β†’ download:


Qt history

after Download :  qt-online-installer-windows-x64-*.exe

Step 2 β€” Run & Log In

Double-click the installer β†’ log in or create a free Qt account β†’ select “Qt for open-source development” β†’ accept LGPL license.

Step 3 β€” Select Components

Qt
└── Qt 6.x.x  (latest stable)
    β”œβ”€β”€ MSVC 2022 64-bit        ← if you have Visual Studio installed
    β”œβ”€β”€ MinGW 13.1.0 64-bit     ← recommended for beginners (compiler bundled)
    └── Qt Creator              ← IDE (auto-selected)

Developer and Designer Tools
└── MinGW 13.1.0 64-bit         ← the actual MinGW compiler toolchain

Tip: No Visual Studio? Use MinGW β€” the compiler ships with Qt, nothing extra needed.

Step 4 β€” Install

Click Next β†’ Install and wait 10–30 minutes depending on your connection.

Step 5 β€” Verify

Open Qt Creator β†’ Edit β†’ Preferences β†’ Kits β€” you should see a kit with a green checkmark. If not, see the Kit Fix note below.

# Optional β€” verify from command line (Qt MinGW shell)
qmake --version
# Output: QMake version 3.x  /  Using Qt version 6.x.x

4.2 Linux (Ubuntu / Debian)

Option A β€” Online Installer (Latest Qt 6, full control)

# Make executable and run
chmod +x qt-online-installer-linux-x64-*.run
./qt-online-installer-linux-x64-*.run

Select the same components as Windows above (GCC 64-bit instead of MinGW).

Option B β€” Package Manager (Faster, Ubuntu/Debian)

sudo apt update
sudo apt install qt6-base-dev qt6-tools-dev qt6-tools-dev-tools qtcreator
sudo apt install qt6-declarative-dev       # Qt Quick / QML support
sudo apt install libqt6serialport6-dev     # Serial port (for embedded use)

Verify

qmake6 --version
# QMake version 3.x  /  Using Qt version 6.x.x

qtcreator &
# Qt Creator should open

4.3 macOS

Requirements: macOS 11+ Β· Intel or Apple Silicon (M1/M2) Β· ~10 GB free disk

Step 1 β€” Install Xcode CLI Tools

xcode-select --install

Wait for the popup and click Install (~5 minutes).

Step 2 β€” Download the Installer

Go to qt.io/download β†’ Open Source β†’ download:

qt-online-installer-mac-*.dmg

Step 3 β€” Select Components

Qt
└── Qt 6.x.x
    └── macOS               ← works on both Intel and Apple Silicon

Developer and Designer Tools
└── Qt Creator

Apple Silicon (M1/M2): Qt 6.2+ includes native ARM64 support β€” make sure you download the ARM64 variant of the installer.

Step 4 β€” Verify

/path/to/Qt/6.x.x/macos/bin/qmake --version
# Using Qt version 6.x.x

Kit Fix

If Qt Creator shows no kit or a red/yellow warning:

  1. Go to Edit β†’ Preferences β†’ Kits
  2. Click Add
  3. Set:
    • Compiler: MinGW 13.1.0 64-bit (Windows) or system GCC (Linux/macOS)
    • Qt version: Browse to qmake in your Qt install folder
  4. Click OK β€” the kit should turn green

What You Should Have After Setup

ToolPurposeCheck Command
Qt 6.x.xFramework librariesqmake --version
Qt CreatorIDEOpens without errors
Compiler (MinGW/GCC/Clang)Builds C++ codeKit shows green in Creator
CMakeBuild systemcmake --version

Apple Silicon (M1/M2): Qt 6.2+ supports native ARM64. Make sure to download the ARM64 variant.


5. Running Your First Qt Program

5.1 Create Project in Qt Creator

1. Open Qt Creator  ==> from File select  New Project

Qt Craetor

3. then Qt Widgets Application
in "Name: HelloQt\nLocation: your folder" 

alt text

then write your Application name and Location 

alt text

then
"Select Kit\nMinGW / GCC / Clang" Class: MainWindow 

alt text

then 

alt text

and Last Finish 

5.2 Project Structure

HelloQt/
β”œβ”€β”€ CMakeLists.txt       ← build system config
β”œβ”€β”€ main.cpp             ← entry point β€” starts the app
β”œβ”€β”€ mainwindow.h         ← MainWindow class declaration
β”œβ”€β”€ mainwindow.cpp       ← MainWindow logic
└── mainwindow.ui        ← UI layout (XML β€” edited via Qt Designer)

5.3 The Code β€” Annotated

main.cpp β€” the entry point

#include <QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);   // manages the event loop + platform setup

    MainWindow window;              // create your main window
    window.show();                  // make it visible

    return app.exec();              // start the event loop β€” blocks here
}

mainwindow.h β€” class declaration

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui { class MainWindow; }

class MainWindow : public QMainWindow
{
    Q_OBJECT                        // REQUIRED β€” enables signals & slots

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    Ui::MainWindow *ui;             // pointer to the generated UI class
};

#endif

mainwindow.cpp β€” implementation

#include "mainwindow.h"
#include "ui_mainwindow.h"          // auto-generated from mainwindow.ui

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);              // load & apply the .ui layout
    setWindowTitle("Hello, Qt!");
}

MainWindow::~MainWindow()
{
    delete ui;
}

5.4 Qt Application Lifecycle

Qt_lifecycle

5.5 Build and Run Shortcuts

ActionQt Creator Shortcut
BuildCtrl+B
Run (build if needed)Ctrl+R
DebugF5
StopCtrl+.

5.6 Hello World β€” Console Only

#include <QCoreApplication>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);   // no GUI β€” use Core not Application

    qDebug() << "Hello, Qt World!";     // cross-platform debug output

    return 0;
}

Use QCoreApplication when there is no GUI. qDebug() is Qt’s cross-platform console output stream.


6. Creating & Running a Qt App β€” Terminal & VSCode

6.1 The CMake Build Pipeline

Every Qt project goes through the same pipeline from source files to a running executable. Here is the full picture:

  Source Files                 CMake Layer                  Output
 ──────────────               ─────────────               ─────────
  main.cpp        ──┐
  mainwindow.cpp  ───         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  mainwindow.h    ─────────►  β”‚ cmake -S . -B  β”‚ ──────►  Makefiles /
  mainwindow.ui   ───  uicβ–Ί   β”‚   build        β”‚           Ninja files
  resources.qrc   β”€β”€β”˜  rccβ–Ί   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  CMakeLists.txt  ────────►          β”‚
                                     β–Ό
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚  cmake --build     β”‚
                            β”‚  g++ / clang++     β”‚
                            β”‚  MSVC              β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
                                     β–Ό
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚  HelloQt.exe       β”‚  ◄── final binary
                            β”‚  HelloQt           β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

What each tool does automatically (via CMake flags):

CMake FlagTool It RunsJob
CMAKE_AUTOMOC ONmocGenerates meta-object code for signals & slots
CMAKE_AUTOUIC ONuicConverts .ui XML β†’ ui_mainwindow.h
CMAKE_AUTORCC ONrccEmbeds .qrc resource files into the binary

6.2 Project File Structure

A minimal Qt Widgets project looks like this on disk:

HelloQt/
β”œβ”€β”€ CMakeLists.txt          ← build configuration
β”œβ”€β”€ main.cpp                ← entry point
β”œβ”€β”€ mainwindow.h            ← window class declaration
β”œβ”€β”€ mainwindow.cpp          ← window class implementation
β”œβ”€β”€ mainwindow.ui           ← Qt Designer XML layout
└── build/                  ← generated β€” never commit this
    β”œβ”€β”€ HelloQt.exe         ← final binary (Windows)
    β”œβ”€β”€ HelloQt             ← final binary (Linux/macOS)
    └── ui_mainwindow.h     ← auto-generated β€” never edit

Rule: Never edit anything inside build/. It is regenerated on every build. Add build/ to your .gitignore.


6.3 Minimal CMakeLists.txt (Annotated)

cmake_minimum_required(VERSION 3.16)
project(HelloQt LANGUAGES CXX)

# ── C++ standard ──────────────────────────────────────────
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# ── Qt automation ─────────────────────────────────────────
set(CMAKE_AUTOMOC ON)   # runs moc on Q_OBJECT classes
set(CMAKE_AUTOUIC ON)   # runs uic on .ui files β†’ ui_*.h
set(CMAKE_AUTORCC ON)   # embeds .qrc resource files

# ── Find Qt 6 ─────────────────────────────────────────────
find_package(Qt6 REQUIRED COMPONENTS Widgets)

# ── Build target ──────────────────────────────────────────
add_executable(HelloQt
    main.cpp
    mainwindow.h
    mainwindow.cpp
    mainwindow.ui       # listed so CMake/AUTOUIC finds it
)

# ── Link Qt libraries ─────────────────────────────────────
target_link_libraries(HelloQt PRIVATE Qt6::Widgets)

6.4 Step-by-Step: Build from Terminal

The same three commands always apply β€” only the -G generator and paths differ per OS.


Step 1 β€” Open the right terminal

  Windows MinGW    β†’  Start Menu β–Ί Qt 6.x.x β–Ί MinGW x.x.x 64-bit
  Windows MSVC     β†’  Start Menu β–Ί Visual Studio β–Ί Developer PowerShell
  Linux / macOS    β†’  any terminal (bash / zsh)

Step 2 β€” Navigate to your project folder

cd ~/projects/HelloQt       # Linux / macOS
cd C:\projects\HelloQt      # Windows

Step 3 β€” Configure (generate build files)

Windows β€” MinGW

cmake -S . -B build -G "MinGW Makefiles"

Windows β€” MSVC

cmake -S . -B build -G "NMake Makefiles"

Linux / macOS

cmake -S . -B build -DCMAKE_PREFIX_PATH=~/Qt/6.x.x/gcc_64

If Qt is not found automatically, add -DCMAKE_PREFIX_PATH=<path-to-Qt-kit> on any platform.

Expected output:

-- The CXX compiler identification is GNU 13.x.x
-- Found Qt6: /home/user/Qt/6.7.0/gcc_64 (found version "6.7.0")
-- Configuring done
-- Build files have been written to: /home/user/projects/HelloQt/build

Step 4 β€” Compile

cmake --build build

Parallel build (faster β€” uses all CPU cores):

cmake --build build -j$(nproc)    # Linux / macOS
cmake --build build -j4           # Windows (set manually)

Expected output:

[ 25%] Automatic MOC for target HelloQt
[ 50%] Building CXX object CMakeFiles/HelloQt.dir/main.cpp.o
[ 75%] Building CXX object CMakeFiles/HelloQt.dir/mainwindow.cpp.o
[100%] Linking CXX executable HelloQt
[100%] Built target HelloQt

Step 5 β€” Run the binary

Linux / macOS

./build/HelloQt

Windows

.\build\HelloQt.exe

On Windows, Qt DLLs must be on PATH. The Qt MinGW shell sets this automatically. If you get a “DLL not found” error run: windeployqt build\HelloQt.exe


6.5 Terminal Command Reference

TaskCommand
Configure (auto-detect Qt)cmake -S . -B build
Configure (explicit Qt path)cmake -S . -B build -DCMAKE_PREFIX_PATH=<qt-path>
Configure β€” MinGW generatorcmake -S . -B build -G "MinGW Makefiles"
Buildcmake --build build
Parallel buildcmake --build build -j$(nproc)
Clean build outputscmake --build build --target clean
Full reset (delete & reconfigure)rm -rf build && cmake -S . -B build
Run β€” Linux / macOS./build/HelloQt
Run β€” Windows.\build\HelloQt.exe
Deploy Qt DLLs β€” Windowswindeployqt build\HelloQt.exe

6.6 VSCode Setup β€” Step by Step

Step 1 β€” Install VSCode Extensions

Open VSCode and install these four extensions (Ctrl+Shift+X to open Extensions panel):

ExtensionPublisherPurpose
C/C++MicrosoftIntelliSense, syntax highlighting, debugging
CMake ToolsMicrosoftConfigure / build / run via CMake
CMaketwxsCMake language support (syntax + snippets)
Qt Toolstonka3000Qt documentation hover, QML support
  Extensions Panel (Ctrl+Shift+X)
  ────────────────────────────────
  Search: "C/C++"       β†’ Install  Microsoft C/C++
  Search: "CMake Tools" β†’ Install  CMake Tools
  Search: "CMake"       β†’ Install  twxs CMake
  Search: "Qt Tools"    β†’ Install  Qt Tools

Step 2 β€” Open Your Project Folder

  File β–Ί Open Folder...  (or drag folder onto VSCode window)
  ──────────────────────────────────────────────────────────
  Select:  C:\projects\HelloQt\   (Windows)
           ~/projects/HelloQt/    (Linux / macOS)

VSCode detects CMakeLists.txt automatically. You will see:

  [CMake Tools] Would you like to configure this project?  [Yes]

Step 3 β€” Select a Kit (compiler + Qt)

  Ctrl+Shift+P  β–Ί  CMake: Select a Kit
  ─────────────────────────────────────
  Options shown:
    βœ“ GCC 13.x.x x86_64-linux-gnu       ← Linux
    βœ“ MinGW 13.x.x for Qt 6.7.0         ← Windows MinGW
    βœ“ Visual Studio 2022 Release - amd64 ← Windows MSVC

If Qt is not found, proceed to Step 4. Otherwise skip to Step 5.


Step 4 β€” Tell VSCode Where Qt Is (if needed)

Create .vscode/settings.json in your project root:

{
    "cmake.configureArgs": [
        "-DCMAKE_PREFIX_PATH=C:/Qt/6.7.0/mingw_64"
    ]
}

Adjust the path for your OS and Qt version:

OSExample path
Windows MinGWC:/Qt/6.7.0/mingw_64
Windows MSVCC:/Qt/6.7.0/msvc2019_64
Linux/home/user/Qt/6.7.0/gcc_64
macOS/Users/user/Qt/6.7.0/macos

Step 5 β€” Build and Run

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚  VSCode Status Bar (bottom of window)               β”‚
  β”‚                                                     β”‚
  β”‚  βš™ Kit: MinGW  |  β–Ά [HelloQt]  |  πŸ”¨ Build  |  β–·  β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  F7         β†’  Build project
  Shift+F5   β†’  Run (no debugger)
  F5         β†’  Run with debugger attached

Step 6 β€” Debug Configuration (Optional)

Create .vscode/launch.json to enable F5 debugging:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Qt Debug",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/HelloQt",
            "MIMode": "gdb",
            "cwd": "${workspaceFolder}",
            "externalConsole": false,
            "setupCommands": [
                { "text": "-enable-pretty-printing", "ignoreFailures": true }
            ]
        }
    ]
}

Windows MinGW: Also add "miDebuggerPath": "C:/Qt/Tools/mingw1310_64/bin/gdb.exe" to point VSCode at the MinGW GDB.


VSCode Keyboard Shortcuts Summary

ActionShortcutNotes
Open ExtensionsCtrl+Shift+XSearch for extensions
Command paletteCtrl+Shift+PAccess all CMake commands
Select KitCtrl+Shift+P β†’ CMake: Select a KitPick compiler + Qt
ConfigureCtrl+Shift+P β†’ CMake: ConfigureRegenerate build files
BuildF7Incremental build
Run (no debug)Shift+F5Launch binary
DebugF5Launch with GDB/LLDB
Toggle terminal`Ctrl+``Open integrated terminal

7. Qt Designer vs Qt Creator

7.1 Side-by-Side Comparison

    
flowchart LR
    subgraph Creator["Qt Creator β€” Full IDE"]
        direction TB
        C1[Code Editor]
        C2[Embedded Qt Designer]
        C3["Build System CMake / qmake"]
        C4[Debugger / Profiler]
        C5[Git Integration]
        C6[Device Deployment]
    end

    subgraph Designer["Qt Designer β€” UI Editor Only"]
        direction TB
        D1["Widget Box Drag and Drop"]
        D2[Form Canvas]
        D3[Property Editor]
        D4[Object Inspector]
        D5[Signal/Slot Editor]
    end

    Creator -- "embeds" --> Designer

Qt CreatorQt Designer
TypeFull IDEUI-only visual editor
PurposeCode Β· Build Β· Debug Β· DeployDesign .ui files visually
Standalone?YesYes β€” also embedded inside Creator
File types.cpp .h .ui .qrc CMakeLists.txt.ui only
Launch pathQt/Tools/QtCreator/bin/qtcreatorQt/6.x.x/<kit>/bin/designer

7.2 Qt Creator β€” Modes & Panels

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Qt Creator                                            β”‚
β”‚                                                        β”‚
β”‚  [Edit Ctrl+2]  [Design Ctrl+3]  [Debug Ctrl+4]       β”‚
β”‚  [Projects Ctrl+5]  [Help Ctrl+6]                     β”‚
β”‚                                                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ File Tree   β”‚  β”‚ Code Editor  β”‚  β”‚ Output Panel β”‚  β”‚
β”‚  β”‚             β”‚  β”‚   / Designer β”‚  β”‚ (Alt+3)      β”‚  β”‚
β”‚  β”‚ main.cpp    β”‚  β”‚   (embedded) β”‚  β”‚              β”‚  β”‚
β”‚  β”‚ mainwindow  β”‚  β”‚              β”‚  β”‚ Build Logs   β”‚  β”‚
β”‚  β”‚ .ui .h .cpp β”‚  β”‚              β”‚  β”‚ App Output   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

7.3 Qt Designer β€” Panel Layout

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Widget Box  β”‚     Form Canvas          β”‚   Properties  β”‚
β”‚ ──────────  β”‚                          β”‚ ────────────  β”‚
β”‚ QLabel      β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  objectName   β”‚
β”‚ QPushButton β”‚  β”‚  Hello, Qt World!  β”‚  β”‚  geometry     β”‚
β”‚ QLineEdit   β”‚  β”‚                    β”‚  β”‚  text         β”‚
β”‚ QComboBox   β”‚  β”‚  [ Click Me ]      β”‚  β”‚  font         β”‚
β”‚ QCheckBox   β”‚  β”‚                    β”‚  β”‚  styleSheet   β”‚
β”‚ QSlider     β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  ...          β”‚
β”‚ QSpinBox    β”‚                          β”‚               β”‚
β”‚ ...         β”‚                          β”‚ Object Tree   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Signal / Slot Editor  β”‚  Action Editor                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

7.4 The Full .ui β†’ Executable Pipeline

    
flowchart TD
    A["Qt Designer\nDrag and drop widgets\nSet objectNames and properties"]
    B["mainwindow.ui\nXML file"]
    C["uic β€” UI Compiler\nrun automatically by CMake AUTOUIC"]
    D["ui_mainwindow.h\nauto-generated β€” never edit manually"]
    E["mainwindow.cpp\ninclude ui_mainwindow.h\nui->setupUi(this)"]
    F["moc β€” Meta-Object Compiler\nCMAKE AUTOMOC"]
    G["moc_mainwindow.cpp\nsignals and slots glue"]
    H["Compiler\ng++ / clang++ / MSVC"]
    I["HelloQt.exe"]

    A -->|save| B
    B -->|uic| C
    C --> D
    D --> E
    E --> H
    F --> G
    G --> H
    H --> I

Rules:

  • Designer owns the layout β†’ C++ owns the logic
  • Never edit ui_mainwindow.h β€” it regenerates every build
  • Every widget’s objectName in Designer becomes ui->name in code

7.5 Signals & Slots β€” How Events Work

    
sequenceDiagram
    participant User
    participant QPushButton
    participant Qt Runtime
    participant MainWindow

    User->>QPushButton: clicks button
    QPushButton->>Qt Runtime: emit clicked()
    Qt Runtime->>MainWindow: invoke connected slot
    MainWindow->>MainWindow: on_myButton_clicked()
    MainWindow->>User: UI updates (label changes etc.)

Three ways to connect:

// 1. Auto-connect (naming convention β€” no code needed)
void MainWindow::on_myButton_clicked()      // on_<objectName>_<signal>
{
    ui->myLabel->setText("Button clicked!");
}

// 2. Explicit connect() in constructor
connect(ui->myButton, &QPushButton::clicked,
        this,         &MainWindow::onButtonClicked);

// 3. Lambda (inline β€” great for simple responses)
connect(ui->myButton, &QPushButton::clicked, this, [this]() {
    ui->myLabel->setText("Lambda clicked!");
});

7.6 Designer Inside Qt Creator β€” Workflow

    
flowchart LR
    A([Open Project]) --> B[Double-click mainwindow.ui]
    B --> C[Creator switches to Design Mode]
    C --> D[Drag widget from Widget Box]
    D --> E[Set objectName in Properties]
    E --> F["Right-click widget\nGo to slot..."]
    F --> G[Select signal e.g. clicked]
    G --> H["Creator jumps to Edit Mode\nGenerates slot stub in .cpp"]
    H --> I[Write your logic in the slot]
    I --> J[Ctrl+R β€” Build and Run]
    J --> K([Window appears])


7.7 Accessing Designer Widgets in Code

// In Designer: QPushButton objectName = "myButton"
//              QLabel     objectName = "myLabel"
//              QLineEdit  objectName = "myInput"

// In mainwindow.cpp β€” access via ui->
ui->myButton->setText("Clicked!");
ui->myButton->setEnabled(false);
ui->myLabel->setText("Hello from code");
QString text = ui->myInput->text();     // read user input

7.8 Launching Standalone Qt Designer

# Windows
C:\Qt\6.x.x\mingw_64\bin\designer.exe

# Linux
~/Qt/6.x.x/gcc_64/bin/designer

# macOS
~/Qt/6.x.x/macos/bin/Designer.app

Standalone Designer is identical to the embedded one in Qt Creator. Use it for UI-only work without the full IDE.


7.9 Which UI Approach to Use?

    
flowchart TD
    Q{What are you building?} --> A
    Q --> B
    Q --> C

    A["Complex form\nMany widgets\nRapid layout prototyping"] --> R1["Use Qt Designer .ui file"]

    B["Dynamic / runtime-created widgets\nSimple 1-2 widget window"] --> R2["Pure C++ β€” no .ui file\nCreate widgets in constructor"]

    C["Modern animated UI\nTouch / mobile interface\nEmbedded HMI screen"] --> R3["QML / Qt Quick\nDeclarative + C++ backend"]


Summary

    
mindmap
  root((Qt Session 1))
    What is Qt
      Cross-platform C++ framework
      GUI Embedded Mobile Web
    Why Qt
      Write Once Run Anywhere
      Signals and Slots
      Best-in-class tooling
    History
      1991 Trolltech founded
      2005 Qt 4 modular
      2012 Qt 5 QML
      2020 Qt 6 C++17
    Setup
      Online Installer
      Windows MinGW or MSVC
      Linux apt or installer
      macOS Xcode plus dmg
    First Program
      QApplication
      MainWindow
      app.exec event loop
    Terminal and VSCode
      CMake build system
      cmake S . B build
      VSCode CMake Tools
      F7 build Shift+F5 run
    Designer vs Creator
      Creator is the full IDE
      Designer edits .ui files
      uic generates ui header
      ui pointer accesses widgets


References

Official Qt Documentation

ResourceURL
Qt 6 Documentation Homehttps://doc.qt.io/qt-6/
Qt 6 Getting Startedhttps://doc.qt.io/qt-6/gettingstarted.html
Qt Modules Overviewhttps://doc.qt.io/qt-6/qtmodules.html
Qt Widgets Modulehttps://doc.qt.io/qt-6/qtwidgets-index.html
QApplication Classhttps://doc.qt.io/qt-6/qapplication.html
QMainWindow Classhttps://doc.qt.io/qt-6/qmainwindow.html
Signals & Slotshttps://doc.qt.io/qt-6/signalsandslots.html
Qt Designer Manualhttps://doc.qt.io/qt-6/qtdesigner-manual.html
Qt Creator Manualhttps://doc.qt.io/qtcreator/

CMake & Build System

ResourceURL
CMake Documentationhttps://cmake.org/documentation/
Qt CMake Manualhttps://doc.qt.io/qt-6/cmake-manual.html
Qt CMake Getting Startedhttps://doc.qt.io/qt-6/cmake-get-started.html
CMAKE_AUTOMOChttps://cmake.org/cmake/help/latest/prop_tgt/AUTOMOC.html
windeployqthttps://doc.qt.io/qt-6/windows-deployment.html

Qt Online Installer

PlatformDownload
All platformshttps://www.qt.io/download-qt-installer
Qt Open Sourcehttps://www.qt.io/download-open-source

VSCode Extensions

ExtensionMarketplace
C/C++ (Microsoft)https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools
CMake Tools (Microsoft)https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools
CMake (twxs)https://marketplace.visualstudio.com/items?itemName=twxs.cmake
Qt Tools (tonka3000)https://marketplace.visualstudio.com/items?itemName=tonka3000.qtvsctools

Community & Learning

ResourceURL
Qt Forumhttps://forum.qt.io/
Qt Examples & Demoshttps://doc.qt.io/qt-6/qtexamplesandtutorials.html
Qt on Stack Overflowhttps://stackoverflow.com/questions/tagged/qt
Qt YouTube Channelhttps://www.youtube.com/@QtStudios