Qt is often used to develop graphic interfaces. Qt contains C ++ libraries for creating graphical interfaces that can be compiled on various operating systems.
Since this compilation requires a lot of computing power, it is advisable for processors with relatively little power to carry out the development and compilation on a host computer and only then to load the finished application onto the target computer.
There are lots of instructions online for developing a Qt application for Raspberry Pi 3 and Pi 4 models. Unfortunately, I couldn't find one that worked flawlessly for the Raspberry Pi 4. These instructions are based on https://www.kampis-elektroecke.de/raspberry-pi/qt/ and are modified in some places so that it worked for me.
Version 5.14.1 is used for Qt, and I use an Ubuntu 18 LTS that is installed in vmware as the host computer for cross-compilation.
Preparing the Raspberry Pi 4
For the basic installation, we need a Raspbian operating system on the Pi 4. I used "2020-02-13-raspbian-buster-lite.img". Downloads and instructions on how to create an SD card with this can be found at https://www.raspberrypi.org/downloads/raspbian/. After switching on the Pi 4, the configuration menu appears, where you can make various settings (e.g., host name, IP address, etc.). For our configuration, we need "SSH" and "GL (Fake KMS)". See the following two screenshots.
- Then enter development sources in /etc/apt/sources.list. Add the following line:
deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
- Then update the system with the following commands:
sudo apt-get update sudo apt-get dist-upgrade sudo reboot sudo rpi-update sudo reboot
- And then install the required Qt and development packages:
Important: Do not create or modify symlinks for EGL and GLES libraries as described in some instructions.
sudo apt-get build-dep qt5-qmake sudo apt-get build-dep libqt5gui5 sudo apt-get build-dep libqt5webengine-data sudo apt-get build-dep libqt5webkit5 sudo apt-get install libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0 gdbserver
- Then also create a directory for RaspberryQt:
sudo mkdir /usr/local/RaspberryQt sudo chown -R pi:pi /usr/local/RaspberryQt
- Update software and install additional packages:
sudo apt-get update sudo apt-get upgrade sudo apt-get install gcc git bison python gperf pkg-config gdb-multiarch
- Generate ssh key for Raspberry and install it on Raspberry:
ssh-keygen -t rsa -C [email protected]
-P "" -f ~/.ssh/rpi_root_id_rsa ssh-keygen -t rsa -C [email protected] -P "" -f ~/.ssh/rpi_pi_id_rsa cat ~/.ssh/rpi_root_id_rsa.pub | ssh [email protected] 'cat >> .ssh/authorized_keys && chmod 640 .ssh/authorized_keys' cat ~/.ssh/rpi_pi_id_rsa.pub | ssh [email protected] 'cat >> .ssh/authorized_keys && chmod 640 .ssh/authorized_keys'
- Download gcc compiler, Qt and symlink script:
mkdir /opt/RaspberryQt cd /opt/RaspberryQt wget http://download.qt.io/archive/qt/5.14/5.14.1/single/qt-everywhere-src-5.14.1.tar.xz wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py
- The files include the cross-compiler for the Raspberry Pi, the Qt version used (here: 5.14.1), and a Python script for replacing symbolic links of files with relative links (will be needed later).
- Download the gcc compiler "rpi-gcc-8.3.0_linux.tar.xz" from https://bugfreeblog.page.link/rasplinuxgcc830 and extract it into the tools directory
- The Qt version will then be extracted, and the name of the compiler used (here: arm-linux-gnueabihf) will be adjusted in the Qt configuration file.
tar xf qt-everywhere-src-5.14.1.tar.xz cp -R qt-everywhere-src-5.14.1/qtbase/mkspecs/linux-arm-gnueabi-g++ qt-everywhere-src-5.14.1/qtbase/mkspecs/linux-arm-gnueabihf-g++ sed -i -e 's/arm-linux-gnueabi-/arm-linux-gnueabihf-/g' qt-everywhere-src-5.14.1/qtbase/mkspecs/linux-arm-gnueabihf-g++/qmake.conf
- Create working directories:
sudo mkdir /opt/RaspberryQt sudo mkdir /opt/RaspberryQt/build sudo mkdir /opt/RaspberryQt/sysroot sudo mkdir /opt/RaspberryQt/sysroot/usr sudo mkdir /opt/RaspberryQt/sysroot/opt sudo chown -R 1000:1000 /opt/RaspberryQt
- The libraries used by the target machine (here: the Raspberry Pi) are also required. These can be downloaded from the Raspberry Pi using rsync.
rsync -avz [email protected]
:/lib sysroot rsync -avz [email protected] :/usr/include sysroot/usr rsync -avz [email protected] :/usr/lib sysroot/usr rsync -avz [email protected] :/opt/vc sysroot/opt
- However, before the files can be used, the symbolic links that still point to the file system of the Raspberry Pi must be replaced by relative links from the new sysroot directory. This is done using the downloaded Python script:
sudo chmod +x sysroot-relativelinks.py ./sysroot-relativelinks.py sysroot
- Finally, Qt is also configured:
cd /opt/RaspberryQt/build ../qt-everywhere-src-5.14.1/configure -release -opengl es2 -eglfs -device linux-rasp-pi4-v3d-g++ -device-option CROSS_COMPILE=/opt/RaspberryQt/tools/rpi-gcc-8.3.0/bin/arm-linux-gnueabihf- -sysroot /opt/RaspberryQt/sysroot -prefix /usr/local/RaspberryQt -opensource -confirm-license -skip qtscript -skip qtwayland -skip qtwebengine -nomake tests -nomake examples -make libs -pkg-config -no-use-gold-linker -v -recheck make -j4 make install
- The fully compiled Qt libraries are then copied to the Raspberry Pi using rsync:
cd /opt/RaspberryQt rsync -avz sysroot/usr/local/RaspberryQt [email protected]
Installing Qt Creator
The best way to develop Qt applications is to use Qt Creator. To install it, please download and run the online installation files from the Qt website.