Qt Cross-Platform UI in C++
Qt is a cross-platform UI framework native to C++. It provides widgets,
layouts, signals and slots, and is supported by CMake integration through
qmake detection.
CMake Setup
When qmake is in the PATH, CMake detects Qt location automatically.
Otherwise, specify the path explicitly:
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=$QT6_DIRQt modules must be linked to executables via target_link_libraries:
add_executable(test_GearParamInput
src/ui/tests/test_GearParamInput.cpp
src/ui/OutputDirSelect.cpp)
target_link_libraries(test_GearParamInput
PRIVATE Qt6::Widgets Qt6::Core Qt6::Gui)MOC (Meta-Object Compiler)
For Qt’s signal/slot mechanism to work with QObject-derived classes, MOC
must process the header files. All source files included in the executable
should include only headers — never .cpp files — to ensure MOC runs
correctly.
Using Qt Widgets
Each Qt class lives in its own header. Import the header for each widget used:
#include <QWidget>
#include <QFormLayout>Each QWidget has a layout manager. Common layouts include QFormLayout,
QVBoxLayout, and QHBoxLayout. Qt’s official documentation provides the
definitive reference for widget properties, signals, and slot signatures.