Skip to content
Frank Bauernöppel edited this page Dec 7, 2018 · 38 revisions

Qt is a great framework for creating (not only) embedded applications with appealing GUIs. The apps are traditionally written in C++, but GUI design can be done in QML, a descriptive language. There is a rich library of platform independent C++ classes, somehow comparable to JAVA or .NET. Read more on the homepage https://www.qt.io/ and in http://doc.qt.io/qt-5/embedded-linux.html.

For small full-screen 2D graphics projects you might consider SDL2.

Image with Qt5

The rpi-avg-image can be built with Qt5 support: EGLFS ( EGL) should configured as graphical backend, aka QPA (Qt Platform Abstraction), and OpenGL ES 2.0 (OpenGL) will be used for hardware accelerated drawing.

For bitbakeing Qt recipes, the currently used branch of the Qt5 layer git://github.com/meta-qt5/meta-qt5.git must be cloned into the recipes folder:

.../recipes$ git clone -b rocko git://github.com/meta-qt5/meta-qt5.git

and the meta-qt5 layer must be added to bblayers.conf:

...
  \
  ${YOCTOROOT}/recipes/meta-qt5 \
...

Qt5 related packages must be included in the rpi-image-avg.bb recipe, like:

IMAGE_INSTALL_append += " \
    packagegroup-qt5 \
"

packagegroup-qt5 contains a rather long list of modules, so you might want to select your favorites here, see the recipe in .../recipes/meta-raspberrypi-avg/recipes-core/packagegroups or add even more.

Qt examples

rpi-avg-image comes with several examples:

  • qt5-opengles2-test -platform eglfs
  • Qt5_CinematicExperience -platform eglfs
  • BasicQuick -platform eglfs
  • pushd /usr/share/qtsmarthome-1.0/; ./smarthome -platform eglfs; popd

Instead of specifying the graphical backend as a parameter -platform eglfs you may set an environment variable:

export QT_QPA_PLATFORM=eglfs
root@raspberrypi3:~# /usr/share/cinematicexperience-1.0/Qt5_CinematicExperience 

On the HDMI monitor, you should see a smooth rendering with 60 fps and, with htop, only a moderate CPU usage of some 20%. A USB mouse or a touchscreen are recommended for user input.

Build a demo app on RasPi

see the qqtest example under Building Qt Apps on the RPi in https://jumpnowtek.com/rpi/Qt5-and-QML-Development-with-the-Raspberry-Pi.html

Build a test app on the build host.

This is a cross-compilation process.

when a recipe already exisits

From a bitbake shell:

frank@FrankBuntuSSD:~/raspi/build$ bitbake qt5-opengles2-test

The output package resides in one of the ${BUILDDIR}/tmp/deploy/ipk/* folders. This time we don't use the package server, but a mere copy over the network (adjust IP address accordingly):

frank@FrankBuntuSSD:~/raspi/build$ scp ${BUILDDIR}/tmp/deploy/ipk/*/qt5-opengles2-test_1.0.4*.ipk root@192.168.2.105:/home/root

On the RasPi install the package:

root@raspberrypi3:~# opkg install qt5-opengles2-test_1.0.4+gitr0+9383905070-r0_cortexa7hf-neon-vfpv4.ipk 

and start it:

root@raspberrypi3:~# qt5-opengles2-test 

Watch the output on an attached HDMI monitor. Its a quite simple test app only, but it demonstrates that all APIs needed are functional. I might be useful to study its recipe under sources/meta-qt5/recipes-qt/examples/qt5-opengles2-test_git.bb.

when no recipe exists

You have to write one. See https://github.com/FrankBau/meta-raspberrypi-avg/tree/rocko/recipes-example/qt5 for an example.

Build a SDK for cross-compilation

An SDK (Software Development Kit) enables cross-compilation from other Linux hosts, not necessarily the host on which Yocto is installed and where the SDK was built.

The SDK is bitbaked by the following command:

frank@FrankBuntuSSD:~/raspi/build$ bitbake meta-toolchain-qt5

The result is a huge shell archive file poky-glibc-x86_64-meta-toolchain-qt5-cortexa7hf-neon-vfpv4-toolchain-2.4.4.sh in the build folder tmp/deploy/sdk.

When this file is executed on a Linux build host, it installs a SDK for cross-compilation of Qt5 applications on the build host.

SDK cross-compilation from command line

There is a environment setup script in the SDK installation folder which must be source'd first. Then, the cross-compilation toolchain is available on the path.

SDK integration into Qt5 QtCreator

With the SDK, it is also possible to use the Qt IDE qtcreator for software development. When properly configured, qtcreator can deploy your app to an attached Raspi via network (sftp) and even remotely debug it over the network.

further reading