Qt on the Raspberry Pi 2
By Jeff Tranter | Wednesday, April 29, 2015
The Raspberry Pi 2 computer, released in February 2015, is the latest generation of Raspberry Pi hardware.
It is a significantly faster machine than the original Raspberry Pi, with a new Broadcom BCM2836 system on a chip that has a quad-core ARM Cortex A7 CPU running at 900 MHz. The GPU is a VideoCore IV dual-core GPU, the same as on the original Raspberry Pi.
RAM has been increased from 512 MB to 1 GB, and the number of USB ports from two to four.
The video support is unchanged, although the composite video output is now provided via a 3.5mm TRRS jack that also provides audio out, rather than the previous separate audio and video RCA jacks.
File storage uses a MicroSD slot rather than the SD slot in the original Raspberry Pi.
Power consumption is a little higher than the Raspberry Pi 1 model B+, at four watts.
It has the same basic board footprint and GPIO connector pinout as the Raspberry Pi model B+.
Best of all, it still sells for the same price as the original Raspberry Pi: US$35.
While it depends on the benchmark program you run, the new CPU on the Raspberry Pi 2 is roughly six times faster than the original Raspberry Pi. This means that it is now suitable for some applications where the Raspberry Pi was previously too slow. As a desktop, it is now much more responsive and able to run more applications simultaneously with good performance.
What interests me, as a developer, is that the increased performance of the Raspberry Pi 2 means that it is now more suited as a software development machine. Typically, when building C or C++ code for the Raspberry Pi, you would cross-compile it on a fast desktop system. While you can compile natively on the machine, for larger programs it was very slow. Building Qt 5 natively, even on an overclocked Raspberry Pi 1, literally takes several days.
I recently acquired a Raspberry Pi 2 (which took some time, as the initial stock of 150,000 units available on launch day was quickly snapped up. They are now being manufactured at a rate of 20,000 per day). One of the first things I thought I would try was to build Qt 5 natively.
I was using the Raspbian Linux distribution, which is the preferred operating system for the Raspberry Pi. There are other options available, including Windows 10 in the future.
As discussed in some previous blog posts, Qt version 4 is available as standard Raspbian packages and works out of the box on the Raspberry Pi 2. However, Qt 5 is not yet packaged for Raspbian, so you need to build it yourself. Note that if you have both Qt 4 and Qt 5 installed on your system, to avoid confusion you should take care to note which versions of tools, such as qmake, you are running.
Raspbian Linux on the Raspberry Pi is essentially the same as any other desktop Linux system, and Qt can be built simply by installing the necessary compiler and development packages, running the configure script, and then running "make". This will work out of the box for the X11-based xcb back end for Qt, but a little more configuration is currently needed if you want support for OpenGL.
There are some instructions (1) for building Qt 5 natively on the Qt Wiki server. These work for the Raspberry Pi 2.
If you have correctly configured Qt, the output of the configure program should include these lines in the output:
QPA backends: EGLFS ................ yes LinuxFB .............. yes XCB .................. yes (system library)
I initially built Qt 5.4.1, currently the latest release of Qt. It takes about four hours to build the basic Qt libraries. To build everything, including the large modules like QtWebKit and QtWebEngine and all of the example and demos, can take about eight hours. I built Qt using the command "make -j4" to run up to four parallel jobs, taking advantage of the four CPU cores available on the Raspberry Pi 2. You can expect build times to vary slightly, depending on the speed of your SD card.
There are currently some limitations to note with Qt 5 on the Raspberry Pi 2. Both the xcb and eglfs back ends for Qt are available.
The xcb back end supports widget applications and supports the X11 window manager running on the desktop so Qt-based applications will run in a window, which can be moved or resized. However, the OpenGL implementation on the Raspberry Pi is not compatible with xcb or X11, so applications that use OpenGL will not work with the xcb back end.
The eglfs back end supports widget-based and QML applications, and uses OpenGL, but will run in full screen mode and not be aware of any window manager.
The linuxfb back end, which directly uses the Linux video frame buffer, should also be available and work, although you will probably need to set some environment variables in order for the keyboard and mouse devices to work correctly.
You can select which back end to use at run time using command line options, i.e. "-platform xcb" or "-platform eglfs". Normally, the default is to use the eglfs back end.
I also built the Qt 5.5.0 alpha release. It built fine, but there was a problem: the applications run with the xcb back end were exiting immediately. It turned out that there was an assertion check for OpenGL in the back end code that would exit if OpenGL support was not present. That check is unnecessary and has since been removed and the issue should be fixed in the Qt 5.5.0 beta and later releases.
I noticed that in the Qt 5.5.0 alpha release there is a new mkspec file in qtbase/mkspecs/devices/linux-rasp-pi2-g++ for the Raspberry Pi 2. This can be used when cross-compiling Qt for the Raspberry Pi 2. It may need some adjustments, as it is still a work in progress.
In the future, the Raspberry Pi may be moving to a new desktop called Maynard that runs on Wayland (which is the new replacement for X11). Qt has support for Wayland, and getting Wayland running on the Raspberry Pi was covered in a previous blog post. However, the version of Wayland in Raspbian Linux appears to be too old to work with Qt's Wayland module, so this does not currently build.
The new Raspberry Pi 2 is a significantly faster and more powerful platform, while remaining hardware and software compatible with the original Raspberry Pi and selling for the same price. The new performance is already opening up new applications for the platform.
To date, more than five million Raspberry Pi devices have been sold, and the Raspberry Pi 2 will likely increase the rate of sales.
Thanks goes to my colleague Val Vachaev for helping with the configuration and build of Qt 5 on the Raspberry Pi 2.
- Native Build of Qt 5 on a Raspberry Pi, Qt Wiki page, accessed 2 Apr 2015, wiki.qt.io/Native_Build_of_Qt5_on_a_Raspberry_Pi