Qt in Cpp

Qt is a robust cross-platform UI framework which is native to C++.

Setup

On Linux, having qmake in the PATH variable will allow cmake to automatically detect Qt location. Following which, the Qt modules need to be linked to the executables. For example in GearLab:

# ---- Manual tests for UI ----
add_executable(test_GearParamInput
    ${CMAKE_SOURCE_DIR}/src/ui/tests/test_GearParamInput.cpp
    ${CMAKE_SOURCE_DIR}/src/ui/OutputDirSelect.cpp)
target_link_libraries(test_GearParamInput PRIVATE Qt6::Widgets Qt6::Core Qt6::Gui)

It is impossible to add all required C++ files to the executables for MOC to work with QOBJECT. The includes in all of these files should only include headers and no .cpp file.

If qmake is not in the path, then path should be specified while running cmake.

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$QT6_DIR

Using Qt

The individual classes in Qt are all stored in separate headers, Import these headers for each class to be used.

Once the classes are imported, the Qt documentation can be used to create QWidgets which can be embedded into windows to make an application.

Each QWidget has a layout, which can be created using different types such as QFormLayout.