Skip to content
Adam Lee edited this page Aug 31, 2015 · 7 revisions

Qt5 Hello World Native Development Example

Prepare the system

With the right Qt5 tools installed in a Gumstix system, you can natively compile Qt5 applications. Download, flash, and boot this Gumstix Qt5 equipped development image. It is preloaded Qt5 library and toolchains, ready to be used. The flashing procedure is the same as other Gumstix images.

Note: You can install Qt5 packages through the Gumstix Package Repository, but this takes a very long time. Hence a dedicated image for Qt5 development. The details on gumstix-qt5-dev-image is found here.

Write Code

Once you boot your Gumstix system with the special Qt5 image, you can use the Qt5 toolchains to natively configure and compile our "Hello World" application. Note that everything on this section is done on your Gumstix COM, not on your workstation.

First create a file with this source code:

$ wget https://gist.githubusercontent.com/adam-lee/634d9a442a753cbe9b48/raw/220edc9f781c239cbc7711fcb8efa3ba9a537d2f/qt5-test.cpp

Compile Code

Before we use the Qt5 toolchain, let's tell the bash shell where to look for Qt5:

$ export PATH=$PATH:/usr/bin/qt5

Then we can create a Qt Project file, which will be necessary to generate a Makefile:

$ mkdir qt5-test && cd qt5-test
$ qmake -project
$ ls
qt5-test.pro qt5-test.cpp

The Qt Project file qt5-test.pro needs to know more about the modules we need in order to develop our Hello World app. Add core, widgets, and gui modules to the project file:

$ echo 'QT += core widgets gui' >> qt5-test.pro

Now we can do the following:

$ qmake
$ ls
Makefile   qt5-test.cpp qt5-test.pro

Finally you can run make to compile the code:

$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I.
-I/usr/include/qt5 -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I.
-I/usr/lib/qt5/mkspecs/linux-g++ -o qt5-test.o qt5-test.cpp
g++ -Wl,-O1 -o root qt5-test.o   -L/usr/lib -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread 

Run the Code

Before we run the executable on your Gumstix, let's set the target display for our Qt5 application to use:

$ export DISPLAY=:0
$ qt5-test -platform linuxfb

Qt5 Hello World Cross Development Example

Install Qt5 SDK

Download and install the Qt5 specific SDK from [Gumstix Software] page to your Linux workstation (such as Ubuntu 14.04 or 15.04). Note that this is different from the standard SDK. meta-qt5 layer does not yet support the standard Yocto SDK generation class. A Qt5 specific SDK is therefore available.

Running the .sh file will prompt for an install location:

Enter target directory for SDK (default: /opt/poky/1.8):

Once you pick a location, hit enter to complete the process.

Use Qt5 SDK

Source the SDK environment variables:

source /opt/poky/1.8/environment-setup-cortexa8hf-vfp-neon-poky-linux-gnueabi

This sets up cross-toolchain included in the Qt5 SDK. You will notice the toolchain is ready to use:

$ which qmake
/opt/poky/1.8/sysroots/x86_64-pokysdk-linux/usr/bin/qt5/qmake

Compile Code

Using the source code from here, let's cross-compile:

$ qmake -project
qt5-test$ ls
qt5-test.cpp  qt5-test.pro
qt5-test$ echo 'QT += core widgets gui' >> qt5-test.pro
qt5-test$ qmake
qt5-test$ ls
Makefile  qt5-test.cpp  qt5-test.pro
qt5-test$ make
arm-poky-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi -c -pipe  -O2 -pipe -g -feliminate-unused-debug-types -O2 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5 -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtWidgets -I/opt/poky/1.8/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtGui -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/qt5/QtCore -I. -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/lib/qt5/mkspecs/linux-oe-g++ -o qt5-test.o qt5-test.cpp
arm-poky-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-O1 -o qt5-test qt5-test.o   -L/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/lib -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread 

By now, you should have an ARM compatible executable build by your x86 system:

file qt5-test
qt5-test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, BuildID[sha1]=83e227e9309809b26394c0fe6a8fc07caa0b3d5c, not stripped

Run the Code

Copy the binary to your Gumstix system. There are a couple ways to copy files. Here is one using SCP:

$ scp qt5-test [email protected]:/home/root/

Then you can run this executable from your Gumstix system:

$ export DISPLAY=:0
$ export QT_QPA_PLATFORM = linuxfb
$ qt5-tes

QtCreator

Please take a look at this page for a guide on QtCreator configuration of remote development.