Before launching Qt Creator, we check whether we are able to build and launch a Qt application manually. We will build a Qt hello world application. Here is the code for qt_hello_world.cpp:
#include <QApplication> #include <QPushButton> int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton hello("Hello world!"); hello.show(); return app.exec(); }
To build it, we use the SDK installed, as described previously:
$ . /opt/poky/2.4/environment-setup-cortexa9hf-neon-poky-linux-gnueabi
$ qmake -project
$ qmake
This uses qmake to create a project file and a Makefile file with all the relevant code files in the directory. We can now build with the following command:
$ make
qt_hello_world.cpp:1:10: fatal error: QApplication: No such file or directory
To fix it, we need to add the following to the auto-generated qt_hello_world.pro file:
QT += widgets
To run it, we first need to build a filesystem with Qt support. When compiling a Qt application with a Yocto recipe, the build system will automatically install the needed libraries in the target image. On this occasion we will add some Qt example applications to core-image-base so the Qt libraries are also installed. We first prepare the environment as follows:
$ cd /opt/yocto/fsl-community-bsp/
$ source setup-environment wandboard
Then, we configure our project so that the qtbase-examples package is built and included in the image by adding the following to the conf/local.conf file:
PACKAGECONFIG_append_pn-qtbase = " fontconfig examples" IMAGE_INSTALL_append = " qtbase-examples"
We can then build it with the following command:
$ bitbake core-image-sato
Once finished, we can program the microSD card image and boot the Wandboard. Copy the qt_hello_world binary to the target and run the following:
# DISPLAY=:0 qt_hello_world
You should see the Qt hello world window on the X11 desktop.