There's more...

We can now complement our framebuffer image with Qt5 applications. Prior to the Qt5 release, Qt had its own window system implementation (QWS). Qt5 uses Qt platform plugins instead:

  • For single-process applications with one main window, Qt5 recommends the EGLFS plugin, which uses the underlying graphical hardware acceleration, but can use others such as LinuxFB or DirectFB
  • For multiple graphical processes the Wayland plugin must be used

EGL is an interface between OpenGL ES and the native windowing system (like X11 or Wayland) and EGLFS is the platform plugin that runs Qt5 applications over EGL and OpenGL ES 2.0 without a windowing system. EGLFS will force the first window to become full screen and become the root widget window. EGLFS supports only one native full-screen GL window.

The LinuxFB plugin writes directly to the framebuffer using the fbdev Linux subsystem. As such it only supports software rendering and has a limited performance. To compile the Qt hello world application we saw in the Developing Qt applications recipe earlier in this same chapter, we could use the following meta-custom/recipes-qt/qt-helloworld/qt-helloworld_1.0.bb Yocto recipe:

DESCRIPTION = "Simple QT helloworld example"                                     
SECTION = "examples"                                                             
LICENSE = "MIT"                                                                  
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" 

SRC_URI = "file://qt_hello_world.cpp file://qt_hello_world.pro"
DEPENDS += "qtbase fontconfig"
S = "${WORKDIR}"
inherit qmake5
do_install() { install -d ${D}${bindir} install -m 0755 qt_hello_world ${D}${bindir} }

Here, the meta-custom/recipes-qt/qt-helloworld/qt-helloworld-1.0/qt_hello_world.cpp source file is as follows:

#include <QApplication> 
#include <QPushButton> 
 
 int main(int argc, char *argv[]) 
 { 
     QApplication app(argc, argv); 
 
     QPushButton hello("Hello world!"); 
 
     hello.show(); 
     return app.exec(); 
 } 

The meta-custom/recipes-qt/qt-helloworld/qt-helloworld-1.0/qt_hello_world.pro project file is as follows:

SOURCES +=   
   qt_hello_world.cpp 
QT += widgets 

The previous recipe just inherits the qmake5 class with the tools needed for the compilation and a couple of dependencies, the qtbase package and fontconfig, which is the Qt preferred way to access system fonts. If space is a concern, fontconfig may be omitted and Qt will use both pre-rendered and TrueType fonts available at its lib/fonts directory.

Qt5 is very modular so the DEPENDS variable will need to be extended to include all the relevant Qt5 modules. The meta-qt5 layer has examples that can be used as a reference.

Then, we add the qt-helloworld package to the image by using the following in your project's conf/local.conf file:

IMAGE_INSTALL_append = " qt-helloworld" 

Next, we build the image with the following:

$ bitbake fsl-image-multimedia

We can then program the microSD card image, boot it, log in to the Wandboard, and launch the application by running:

# export QT_QPA_PLATFORM="eglfs"
# /usr/bin/qt_hello_world

The QT_QPA_PLATFORM environment variable mentioned previously is used to select the EGLFS plugin. It can also be passed to the application on the command line using the -platform argument.

When exploring the capabilities of Qt5 it is useful to take a look at the available examples. The recipes-qt/packagegroups/packagegroup-qt5-examples.bb packagegroup recipe shown next can be used to add some examples to an image:

SUMMARY = "QT5 examples packagegroup"                                            

inherit packagegroup
RDEPENDS_${PN} = " liberation-fonts icu qtbase-examples qt3d-examples qtconnectivity-examples qtdeclarative-examples qtdeclarative-tools qtmultimedia-examples qtsvg-examples cinematicexperience qt5-demo-extrafiles qt5everywheredemo qtsmarthome "

To build the preceding code, we also need to configure qtbase and qtmultimedia by adding the following PACKAGECONFIG switches to the conf/local.conf file in our build directory:

PACKAGECONFIG_append_pn-qtbase = " accessibility examples fontconfig sql-sqlite icu" 
PACKAGECONFIG_append_pn-qtmultimedia = " gstreamer" 

These could also be added as bbappends to the corresponding recipes.

The different examples are installed on the target root filesytem under /usr/share.

You may encounter the following error while building:
/opt/yocto/fsl-community-bsp/wandboard/tmp/work/cortexa9hf-neon-poky-linux-gnueabi/qtdeclarative/5.9.2+gitAUTOINC+7c45b035b9-r0/git/tests/benchmarks/qml/binding/tst_binding.cpp:175:10: fatal error:tst_binding.moc: No such file or directory| #include "tst_binding.moc"
If this is the case, you may need to remove the tests pkgconfig configuration item from the qtbase package as done in the following patch:
https://github.com/yoctocookbook2ndedition/meta-qt5/commit/331f0e8e0428927594c4b8a2790df2f881fd4663
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset