Notes about Qt

Helpful guides and tricks:

Building Qt 5.15.2 for the same architecture you're currently on

# Enable the sources repositories
sudo apt build-dep qt5-default
sudo apt install libglu1-mesa-dev freeglut3-dev mesa-common-dev libgles2-mesa-dev libglfw3-dev '^libxcb.*-dev'
export CC_FOLDER=/home/developer/crosscompile/5.15.2
../qt-everywhere-src-5.15.2/configure -release -skip qtwebengine -skip qtlocation -skip qtwayland -opengl es2 -make libs -prefix /opt/Qt5.15.2 -extprefix $CC_FOLDER/qt5manta -hostprefix $CC_FOLDER/qt5 -fontconfig
make -j8
make install
# Packages required for a target system
sudo apt install libglu1-mesa freeglut3 libgles2-mesa libglfw3 '^libxcb.*'

Building Qt6 on Raspberry Pi 4

This is for building on the Pi natively, not a cross-compiled build.

# Make sure software repos are updated.
sudo apt update
 
# Update system before proceeding - reboot would probably be good.
sudo apt upgrade
 
# Install general build tools
sudo apt install build-essential ninja-build file clang-11 -y
 
# OPTIONAL: Install some nice-to-have tools
#	- libswt-gtk-4-java is required for SmartGit
#	- micro is a better text editor than nano (has real shortcuts!)
#	- meld is a GUI diff program
sudo apt install -y libswt-gtk-4-java micro meld
 
# Install a version of cmake that's at least >=3.21
mkdir cmaketemp && cd cmaketemp
 
# Download CMake
wget https://github.com/Kitware/CMake/releases/download/v3.24.0/cmake-3.24.0.tar.gz -O cmake.tar.gz
 
# Extract CMake
tar xf cmake.tar.gz
 
# Make a build folder
mkdir build && cd build
 
# Build CMake
../cmake-3.24.0/bootstrap --prefix=/opt/cmake --parallel=4 && make -j4
 
# Install CMake
sudo make install
 
# Update PATH to include CMake's install folder
export PATH=/opt/cmake/bin:$PATH
 
# Install dev packages that Qt requires
sudo apt install mesa-utils libglfw3-dev libgles2-mesa-dev libgbm-dev libdrm-dev libclang-11-dev libfontconfig1-dev libdbus-1-dev libfreetype6-dev libicu-dev libinput-dev libxkbcommon-dev libsqlite3-dev libpng-dev libssl-dev libjpeg-dev libglib2.0-dev 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 -y
 
# Per the tal.org tutorial, libzstd-dev can cause issues (I've seen that in Qt 5.15 too) so we make sure to remove it
sudo apt remove libzstd-dev
 
# Set Qt version
export QTVERSION=6.2.4
 
# Download Qt source code
wget https://download.qt.io/official_releases/qt/6.2/$QTVERSION/single/qt-everywhere-src-$QTVERSION.tar.xz
 
# Extract code
tar xf qt-everywhere-src-$QTVERSION.tar.xz
 
# Rename folder for ease of use
mv qt-everywhere-src-$QTVERSION qtsrc
 
# Make a dir for building
mkdir build && cd build
 
# Configure Qt
../qtsrc/configure -egl -gbm -kms -skip qtwebengine,qtlocation,qtopcua,qttranslations
 
# Build Qt
cmake --build . --parallel
 
# !! IMPORTANT !! Qt 6.2.4 has a bug that in a mkspec file that refers to a non-existent lib
# Edit build/qtbase/mkspecs/modules/qt_lib_core_private.pri
# and change the line that says:
#   QMAKE_LIBS_LIBATOMIC = atomic
# to
#   QMAKE_LIBS_LIBATOMIC = -latomic 
# 
# This is apparently fixed in 6.3.1, but 6.3.1 introduces its own issues (yield instruction error!)
 
# Install Qt
sudo /opt/cmake/bin/cmake --install .
 
# Add the Qt library installation folder to the system lib paths
sudo sh -c "echo /usr/local/Qt-6.2.4/lib > /etc/ld.so.conf.d/Qt-6.2.4.conf"
 
# Update lib paths
sudo ldconfig
 
# OPTIONAL: Build the documentation - good if you're going to run Qt Creator
cmake --build . --parallel 4 --target docs
sudo /opt/cmake/bin/cmake --build . --target install_docs
 
# Set PATH to include cmake and Qt
export PATH=/opt/cmake/bin:/usr/local/Qt-6.2.4/bin:$PATH 

Some other items/commands

To build Qt with the bare minimum (useful for figuring out build errors), you can turn off all of the submodules except qtbase:

../qtsrc/configure -egl -gbm -kms -skip qtwebengine,qtlocation,qtopcua,qttranslations,qtcharts,qtcoap,qttools,qtwebsockets,qtwebchannel,qtsensors,qtserialbus,qtserialport,qtremoteobjects,qtmqtt,qtdoc,qtdeclarative,qtlottie,qtquicktimeline,qtquick3d,qtscxml,qt5compat,qtactiveqt,qt3d,qtconnectivity,qtdatavis3d,qtimageformats,qtnetworkauth,qtpositioning,qtshadertools,qtwayland,qtmultimedia,qtvirtualkeyboard,qtwebview,qtsvg,qtlanguageserver

User Tools