To create a Qt5 for the Raspberry Pi several steps are necessary:
Get the Qt5 sources from git. To checkout Qt5:
git clone http://code.qt.io/cgit/qt/qt5.git
or
git clone http://code.qt.io/qt/qt5.git
The repository might change from time to time. The qt project is still evolving.
Above command in done on the Linux host. To get the dev branch cd to qt5 and:
git checkout dev
followed by
./initRepository
This will take quite some time. In this time the Raspberry Pi root folder can be mounted. It is possible to use a card reader and mount the SD card. A much better solution is to use either nfs, samba, sshfs to mount a life Raspberry Pi. This way minor bugs, e.g. missing dev packages, are easily fixed 'on the fly'.
I use sshfs:
sshfs pi@raspberrypi:/ /home/me/rasp
If this mount is successful, The root file system of the Raspberry Pi is accessible under /home/me/rasp.
As soon as the Qt5 is checked out, the following changes must be made:
In qt5/qtbase/mkspecs the file linux-arm-gnueabi-g++ must be edited (or copied and edited)
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublib
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
# modifications to g++.conf
QMAKE_CC = <path to>/arm-linux-gnueabihf-gcc
QMAKE_CXX = <path to>/arm-linux-gnueabihf-g++
QMAKE_LINK = <path to>/arm-linux-gnueabihf-g++
QMAKE_LINK_SHLIB = <path to>/arm-linux-gnueabihf-g++
# modifications to linux.conf
QMAKE_AR = <path to>/arm-linux-gnueabihf-ar cqs
QMAKE_OBJCOPY = <path to>/arm-linux-gnueabihf-objcopy
QMAKE_NM = <path to>/arm-linux-gnueabihf-nm -P
QMAKE_STRIP = <path to>/arm-linux-gnueabihf-strip
QMAKE_INCDIR_EGL = $$[QT_SYSROOT]/opt/vc/include/EGL/
QMAKE_INCDIR_OPENGL_ES2 = $$[QT_SYSROOT]/opt/vc/include/GLES2/
QMAKE_INCDIR_OPENVG = $$[QT_SYSROOT]/opt/vc/include/VG/
QMAKE_LIBDIR_EGL = $$[QT_SYSROOT]/opt/vc/lib/
QMAKE_LIBDIR_OPENGL_ES2 = $$[QT_SYSROOT]/opt/vc/lib/
QMAKE_LIBDIR_OPENVG = $$[QT_SYSROOT]/opt/vc/lib/
QMAKE_LIBS_EGL = -lEGL -lGLESv2
QMAKE_LIBS_OPENVG = -lOpenVG -lEGL -lGLESv2
QMAKE_LIBS_OPENGL_ES2 = -lEGL -lGLESv2
LIBS += -L$$[QT_SYSROOT]/opt/vc/lib -lvcos -lbcm_host -lvchiq_arm
LIBS += -lEGL -lGLESv2
INCLUDEPATH += $$[QT_SYSROOT]/opt/vc/include
INCLUDEPATH += $$[QT_SYSROOT]/opt/vc/include/interface/vcos
INCLUDEPATH += $$[QT_SYSROOT]/opt/vc/include/interface/vcos/pthreads
INCLUDEPATH += $$[QT_SYSROOT]/opt/vc/include/interface/vmcs_host/linux
<path to> has to be replaced with the cross compiler, which was created according to: How can I create a modern cross compile toolchain for the Raspberry Pi 1?
Next step is to configure Qt5:
./configure -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=<path to>/arm-linux-gnueabihf- -xplatform linux-arm-gnueabi-g++ -sysroot /home/me/rasp -opensource -confirm-license -optimized-qmake -release -make libs -prefix /usr/local/qt5pi -v -libinput -linuxfb -directfb -xcb -fontconfig -ts
lib -evdev -iconv -xinput2 -xkbcommon-evdev -eglfs -icu -qt-pcre -lpthread -system-sqlite -no-sql-sqlite2 -gstreamer 1.0 -reduce-exports
Special attention need the following parameters:
-xplatform linux-arm-gnueabi-g++ This is the mkspec. Change name accordingly, if linux-arm-gnueabi-g++ was not edited, but a new mkspec was created.
-device-option CROSS_COMPILE=<path to>/arm-linux-gnueabihf- Not sure, if this is necessary. Found it in some tutorials. Everything worked fine without this option. Adjust <path to> to cross compiler just as in the mkspec.
-sysroot /home/me/rasp Very important. The mount point where the Raspberry Pi is mounted.
-prefix /usr/local/qt5pi Where the Qt5 is to be installed on the RPi
Now all there is to do is the usual:
make/make install. The command builds Qt5 and installs it in /usr/qt5pi on the Raspberry Pi. Make sure proper write permissions exist for this location.
One more thing:
qtwayland/src/hardwareintegration/client/brcm-egl/qwaylandbrcmeglintegration.h
contained a bug when I compiled my qt5.
A quick fix is to edit this file:
#include <QtWaylandClient/private/qwaylandclientbufferintegration_p.h>
#include <wayland-client.h> <--- add this below the #include above.
One last thing: This qt5 is NOT suitable to be used from within the Raspberry Pi itself. When programs are created, the RPi must be mounted and the compilation must be done under the same host with the same cross compiler on which the Qt5 was compiled.
Another last thing: The RPi does not support xcb. So X11 forwarding is not possible.
EDIT: I have been told this is not true. No, it isn't. However, what is true, the RPi does not support xcb/X11 for programs, which use OpenGL. So no qtquick 2 programs: http://lists.qt-project.org/pipermail/qtonpi/2012-October/001087.html
Nothing to be done about this at the moment, its graphics driver simply don't support it. Wayland support is limited. Best platform to be used is eglfs.