|
Building QT6 from Source on Raspberry Pi

Building QT6 from Source on Raspberry Pi

This article will guide you through building QT6 from source on Raspberry Pi. QT is a cross-platform application framework that allows developers to create user interfaces and applications that run on various platforms, including Raspberry Pi.

Preparation

Hardware Requirements

You need to prepare the following hardware:

  • A Raspberry Pi (32-bit or 64-bit)

  • An SD card with Raspberry Pi OS installed

  • An Ethernet cable or Wi-Fi connection

  • A computer that can access the Raspberry Pi

Software Requirements

You need to install the following software on Raspberry Pi:

  • Raspberry Pi OS (based on Debian 12 Bookworm)

  • Build tools and compiler tools (cmake and ninja-build)

You can install these packages using the following commands:

sudo apt update
sudo apt install build-essential cmake ninja-build

Installing Required Build Dependencies

You need to install a large number of packages to build QT 6.6. Some QT 6.6 features are optional and can be included or excluded based on your specific needs.

First, update your apt package cache:

sudo apt update

Then proceed to install the following required packages:

Development PackageDescription
libfontconfig1-devFont configuration library
libharfbuzz-devOpenType text shaping engine
libdbus-1-devD-Bus library
libfreetype6-devFont engine library
libicu-devUnicode library
libinput-devInput device handling
libxkbcommon-devXKB compiler library
libsqlite3-devsqlite3 database driver
libpng-devPNG image support
libssl-devOpenSSL support
libjpeg-devJPEG image support
libglib2.0-devglib main loop support

You can install all required development packages using the following command:

sudo apt install libfontconfig1-dev libharfbuzz-dev libdbus-1-dev libfreetype6-dev libicu-dev libinput-dev libxkbcommon-dev libsqlite3-dev libssl-dev libpng-dev libjpeg-dev libglib2.0-dev

Raspberry Pi Graphics Environment and Driver Options

In QT 6, you will only be able to use Mesa and V3D, VC4 drivers, as both Raspberry Pi OS and QT 6 have dropped support for Broadcom’s proprietary EGL blob.

Graphics Driver Options

Graphics DriverRequired PackagesDescription
V3D and VC4 driverslibgles2-mesa-dev libgbm-dev libdrm-devQT_FEATURE_kms=ON ** QT_FEATURE_opengles2=ON
QT_FEATURE_opengles3=ON
Vulkan support for V3D driver only on Raspberry Pi 4 and 5libvulkan-dev vulkan-toolsQT_FEATURE_vulkan=ON
X11See belowQT_FEATURE_xcb=ON
WaylandSee belowPlease note that Wayland support is located in the qtwayland submodule.

Optional Basic Feature Dependencies

Some features are not strictly required but may still be practical, such as support for webp image format is optional, but it is now widely used, so it may be best to include it.

The following table lists some optional features and the required development packages to install.

Optional features for basic QT**

Optional FeaturePackages to InstallConfiguration Options
PostgreSQL database supportlibpq-dev
MariaDB /MySQL database supportlibmariadb-dev libmariadb-dev-compat
Printing support using CUPSlibcups2-dev
X11 supportlibx11-dev libxcb1-dev libxext-dev libxi-dev libxcomposite-dev libxcursor-dev libxtst-dev libxrandr-dev libx11-xcb-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libxcb1-dev libxcb-glx0-dev libxcb-keysyms1-dev libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev libxcb-sync-dev libxcb-xfixes0-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-util0-dev libxcb-xinerama0-dev libxcb-xkb-dev libxkbcommon-dev libxkbcommon-x11-dev libxcb-xinput-dev libxcb-cursor-devQT_FEATURE_xcb=ON
Waylandlibwayland-dev
libzstd libzstd-dev
GTK 3 theme supportlibgtk-3-dev
Accessibilitylibatspi2.0-dev
SCTP** Stream Control Transmission Protocollibsctp-devQT_FEATURE_LABEL_sctp

Use apt install to install any packages needed for the features you require from the table above.

Building QT 6.6 Base Modules

QT Base provides the core parts of QT and needs to be built and installed before anything else.

Download QT 6.6 Base Source Code

wget https://download.qt.io/official_releases/qt/6.6/6.6.3/submodules/qtbase-everywhere-src-6.6.3.tar.xz

Configure, Build and Install QT 6.6 Base Modules

Extract the source code:

tar xf qtbase-everywhere-src-6.6.3.tar.xz

Create a build directory:

mkdir qtbasebuild && cd qtbasebuild

Optional: Create a cmake toolchain file

If you are building for a different architecture type than the build system, for example, you will run QT on an armv6-based Pi but build on a faster device (armv7 or armv8), you may need to create a cmake toolchain file.

Note: ** This is not needed if the QT 6 build will run on the same architecture as the build. For example, if you are building on a 32-bit armv7 Pi and intend to run QT on armv7 or later, you don’t need a toolchain file.

To create a cmake toolchain file named tc.cmake, start your preferred editor. Create the file somewhere that won’t be deleted, such as in the install prefix you use, because it will be referenced by QT build files during installation. The file contents depend on the target architecture (Note: only armv7 has been tested):

CMAKE_TOOLCHAIN_FILE Examples

ArchitectureToolchain File Contents
For armv6set(CMAKE_CROSSCOMPILING FALSE) ** set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv6)
set(TARGET armv6-linux-eabi)
For armv7set(CMAKE_CROSSCOMPILING FALSE)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv7)
set(TARGET armv7-linux-eabi)
For armv8set(CMAKE_CROSSCOMPILING FALSE)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv8)
set(TARGET armv8-linux-eabi)
For aarch64TBD

Configuration Options

QT can be customized in various ways when building, the following table shows some options that can be used when configuring the build.

OptionDescription
QT_FEATURE_opengles2=ONUse OpenGL ES 2.0
QT_FEATURE_opengles3=ONUse OpenGL ES 3.0
QT_FEATURE_kms=ONUse kernel mode setting
QT_FEATURE_vulkan=ONUse Vulkan driver
QT_QPA_DEFAULT_PLATFORM=eglfsSet default platform plugin to eglfs
BUILD_WITH_PCH=OFFDisable precompiled headers

Configure QT 6.6 Build

Then run the configuration (adjust prefix as needed, add/remove any configuration options as needed, remove CMAKE_TOOLCHAIN_FILE parameter if not used, etc.):

cmake -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX= */opt/Qt/6.6*  \
-DQT_FEATURE_opengles2=ON \
-DQT_FEATURE_opengles3=ON \
-DQT_FEATURE_kms=ON \
-DQT_FEATURE_xcb=ON \
-DQT_FEATURE_vulkan=ON \
*-DCMAKE_TOOLCHAIN_FILE=tc.cmake*  \
-DQT_AVOID_CMAKE_ARCHIVING_API=ON ../qtbase-everywhere-src-6.6.3

Check the configuration summary output to ensure all required items have been successfully detected, and if successful, you can start building QT.

Build QT 6.6 Base Modules

Next is the actual compilation of the source code, we will use the following command to do this, adjusting the example parallel build (4) as needed.

Note: ** Parallel builds are not recommended on single-core or low-memory systems.

cmake --build . --parallel 4

Install QT 6.6 Base Modules

After the build completes successfully, the next step is to install the results into your system. To install the compiled QT, run:

cmake --install .

Building QT Documentation

QDoc is an essential tool for building and installing documentation for use by various GUI tools. QDoc is part of the qttools submodule and obviously requires QT itself to build. Documentation can be built from the build tree later, so if you do need documentation, don’t delete any build results for now.

Build the documentation using the following command:

cmake --build . --parallel 4 --target docs

And install using the following command:

cmake --build . --target install_docs

Build Time for QT Base Modules

Comparison of build times for QT base modules on various systems

ModulePi 5Pi 432-bit RISC-V SoCRockchip RK3328Pi 3AMD Ryzen 3600X
qtbase~40 minutes~50 minutes~3 hours~6 minutes

Building QT Submodules

You can quickly configure, build and install QT submodules using the following command (why not do it in a simple for loop, I’ll leave that as an exercise for the reader!):

/opt/Qt/6.6/bin/qt-configure-module . && cmake --build . --parallel 4 && cmake --install .

For a more in-depth tutorial on building submodules, see the QT Submodule Build Tutorial.

Conclusion

In this tutorial, we learned how to build QT 6.6 from source on Raspberry Pi. We covered installing necessary dependencies, configuring the build process, and building and installing QT base modules and submodules. You should now be able to develop and run QT-based applications on Raspberry Pi.