This tutorial provides you a step-by-step guide on how to build an up-to-date Qt 6.5 LTS release from source with proper hardware acceleration support for Raspberry Pi on Raspberry Pi OS, both 32-bit and 64-bit, based on Debian 11 Bullseye release. Qt is a popular cross-platform application framework that enables developers to create user interfaces and applications that can run on various platforms, including the Raspberry Pi.
Updated as of Qt 6 release 6.5.1
Guide on how to build Qt 6.5 LTS components for use on a Raspberry Pi running Raspberry Pi OS. The configuration and build differs quite a lot from how Qt 5 was built as the build system is now using cmake and ninja, instead of the older qmake and make combo.
Note: This guide was written for Raspberry Pi OS Bullseye version only
Note: The procedure is exactly the same for both 32-bit or 64-bit versions of Raspberry Pi OS, just adjust any architecture specific paths accordingly.
This tutorial is written for the split components version of Qt 6.5 instead of the all components one. This makes it much faster to get up and running with only the components you actually need. Building Qt 6 for and on the Raspberry Pi is still pretty straightforward, there are some Pi specific configurations that needs to be made, but in short it consist of the following steps:
- Configure Raspberry Pi graphics system to use Mesa/Vulkan driver
- Installing all required build and runtime dependencies for Qt Base
- Installing any optional build and runtime dependencies for Qt Base
- Prepare Qt 6.5 base sources
- Downloading Qt 6.5 base sources
- Checking the Qt 6.5 base source package integrity
- Extract the base sources
- Configuring the Qt 6.5 base build
- Compiling Qt 6.5 base
- Installing the Qt 6.5 base
- Continue to installing any Qt submodules
And for any Qt 6.5 submodules the procedure is about the same as for the base package:
- Install required build and runtime dependencies
- Install optional build and runtime dependencies
- Prepare sources
- Download submodule source archive
- Check integrity of submodule source archive
- Extract submodule source archive
- Configure submodule for building
- Build submodule
- Install submodule
- Select another submoule and goto step 1
Prepare the build tools required
Essentials build packages
As we need to be able to compile and build software from source, make sure all the essential build & compiler tools, cmake and ninja are installed with:
apt install build-essential cmake ninja-build
Install required build dependencies
You will need to install plenty of packages to be able to build Qt 6.5. Some of the Qt 6.5 features are optional and can be either left our or included, depending on your particular needs. For example support for various databases (PostgreSQL, MySQL/MariaDB) and if you don't need a specific feature you can skip building the support. Or the other way around, if you need a specific feature you might need to install more development packages.
First, start by updating your apt package cache so everything is fresh:
Then continue with required package installation below.
|libfontconfig1-dev||Font configuration library|
|libfreetype6-dev||Font engine library|
|libinput-dev||Input device handling|
|libxkbcommon-dev||XKB compiler library|
|libsqlite3-dev||sqlite3 database driver|
|libpng-dev||PNG Image support|
|libjpeg-dev||JPEG Image support|
|libglib2.0-dev||glib mainloop support|
Install all the required development packages with:
apt install libfontconfig1-dev libdbus-1-dev libfreetype6-dev libicu-dev libinput-dev libxkbcommon-dev libsqlite3-dev libssl-dev libpng-dev libjpeg-dev libglib2.0-dev
Graphics driver options
Support for the proprietary EGL blobs from Broadcom has dropped in both Raspberry Pi OS and Qt 6. With Qt 6 you will be using the Mesa and the VC4 driver.
|Graphics driver||Required package(s)||Information|
|libgles2-mesa-dev libgbm-dev libdrm-dev||
Only on Raspberry Pi 4
Optional base feature dependencies
Some features are not strictly required but might still be nice to have, for example support for the webp image format is optional, but these days it is already widely used so might be good to include.
See the table below for a list of some optional features and the required development packages you need to install.
|Optional feature||Packages to install||Configure option|
|Support for database PostgreSQL||
|Support for database MariaDB/MySQL||
Printing support using CUPS
libx11-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-dev
|Note: System version causes issues. Needs to be removed.|
Stream Control Transmission Protocol
Install any required packages for the feature you require from the above table with apt install.
Building Qt 6.5 base
Qt Base provides the core parts of Qt and needs to be built and installed before anything else.
Download Qt 6.5 base sources
Configure, build and install Qt 6.5 base
Extract the sources:
tar xf qtbase-everywhere-src-6.5.1.tar.xz
Create a build directory:
mkdir qtbasebuild && cd qtbasebuild
Optional: Create a cmake toolchain file
You might need to make a cmake toolchain file in case you are building for some other type of architecture than the one you are building on, for example you are going to run Qt on the armv6 based Pis but build on something faster (armv7 or armv8).
Note: This is not needed if the Qt 6 build will be run on the same architecture as the building. For example, you are building on 32-bit armv7 Pi and intend to run Qt on armv7 or above then toolchain file is not required.
To create a cmake toolchain file, tc.cmake, fire up your favorite editor. Create the file somewhere that does not get deleted, for example in the install prefix you use, as it will be referenced by the Qt build files when installed. The contents for the file is, depending on target architecture (Note: only armv7 has been tested):
|Architecture||Toolchain file contents|
set(CMAKE_CROSSCOMPILING FALSE) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR armv6) set(TARGET armv6-linux-eabi)
set(CMAKE_CROSSCOMPILING FALSE) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR armv7) set(TARGET armv7-linux-eabi)
set(CMAKE_CROSSCOMPILING FALSE) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR armv8) set(TARGET armv8-linux-eabi)
Qt can be customized in many ways when building, this table shows some options that you can use when configuring the build.
|QT_FEATURE_opengles2=ON||Use OpenGL ES 2.0|
|QT_FEATURE_opengles3=ON||Use OpenGL ES 3.0|
|QT_FEATURE_kms=ON||Use Kernel Mode Setting|
|QT_FEATURE_vulkan=ON||Use Vulkan driver|
|QT_QPA_DEFAULT_PLATFORM=eglfs||Set default platform plugin to eglfs|
|BUILD_WITH_PCH=OFF||Disable precompiled headers|
Configure the Qt 6.5 build
Then run the configuration (adjusting prefix if needed, add/remove any configuration options as needed, remove CMAKE_TOOLCHAIN_FILE parameter if not used, etc):
/opt/cmake/bin/cmake -G Ninja \ -DCMAKE_INSTALL_PREFIX=/opt/Qt/6.5.1 \ -DQT_FEATURE_opengles2=ON \ -DQT_FEATURE_opengles3=ON \ -DQT_FEATURE_kms=ON \ -DCMAKE_TOOLCHAIN_FILE=tc.cmake \ -DQT_AVOID_CMAKE_ARCHIVING_API=ON ../qtbase-everywhere-src-6.5.1
Check the configuration summary output that everything required was succesfully detected, and if so, you can start the build.
Build Qt 6.5 base
Next up is actually building the sources, that we will do with the following command, adjust the example parallel build (4) as you see fit.
cmake --build . --parallel 4
Install Qt 6.5 base
When the build has successfully finnished, the next step is to install the result to the system. To do that run:
cmake --install .
Building Qt Documentation
QDoc is required for building and installing documentation for use in various GUI tools. QDoc is part of the qttools submodule and obviously requires Qt itself to build. Documentation can be built afterwards from the build tree so if you do need documentation then don't remove any build results just yet.
Documentation is built with:
cmake --build . --parallel 4 --target docs
And installed with:
/opt/cmake/bin/cmake --build . --target install_docs
Building Qt submodules
You can quickly configure, build and install the Qt submodules with (why not do it in simple for loop, I'll leave that as an excerise for the reader!):
/opt/Qt/6.5.1/bin/qt-configure-module . && cmake --build . --parallel 4 && cmake --install .
For a more in-depth tutorial on building sub-modules, see the Qt sub-module building tutorial.