Getting Qt5 with OpenGL ES 2.0 support on Raspberry Pi

A while ago I read about the EGLFS  plugin for QT (which is a GUI library). This plugin enable QT to draw directly to the Linux frame buffer. Which is ideal if you are running a GUI application on a embedded (low on resources) device and don't want the overhead of a full blown X11 + window manager desktop. This tutorial will walk you through the compilation and installation of QT5 (5.2 in my case) on a Raspberry Pi.

First we need to clone the QT5 git repository.  Assuming you're currently in your home directory (~) the following command will clone the QT5 tree into ~/qt5.

git clone git://gitorious.org/qt/qt5.git qt5

As changes are made to this repository my tutorial may break. If this is the case you may try to clone the following commit. Which is the commit I cloned (the latest at the time). https://qt.gitorious.org/qt/qt5/commit/758d922716ebdedeaa6fa26369c8dbb9dff4bae4

The cloning will take a while. QT consists out of lots of files. After the cloning is succeeded you can enter the directory. And checkout the stable branch (you probably already are on the stable branch, but just in case)

cd qt5
git checkout stable

Now we need to configure the tree for our needs. The following commands will achieve this.

./init-repository
./configure -v -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=/usr/bin/ -opensource -confirm-license -optimized-qmake -reduce-relocations -reduce-exports -release -qt-pcre -make libs | tee configure_output

This last command will produce an output as below. Note that OpenGL and EGLFS should be at 'yes'.

Build options:
  Configuration .......... accessibility audio-backend c++11 clock-gettime clock-monotonic compile_examples concurrent cross_compile egl eglfs evdev eventfd freetype full-config getaddrinfo getifaddrs iconv inotify ipv6ifname large-config largefile linuxfb medium-config minimal-config mremap neon nis no-harfbuzz no-pkg-config opengl opengles2 pcre png precompile_header qpa qpa reduce_exports reduce_relocations release rpath shared small-config system-zlib
  Build parts ............  libs
  Mode ................... release
  Using C++11 ............ yes
  Using PCH .............. yes
  Target compiler supports:
    iWMMXt/Neon .......... no/yes

Qt modules and options:
  Qt D-Bus ............... no
  Qt Concurrent .......... yes
  Qt GUI ................. yes
  Qt Widgets ............. yes
  JavaScriptCore JIT ..... yes (To be decided by JavaScriptCore)
  QML debugging .......... yes
  Use system proxies ..... no

Support enabled for:
  Accessibility .......... yes
  ALSA ................... no
  CUPS ................... no
  FontConfig ............. no
  FreeType ............... yes
  Iconv .................. yes
  ICU .................... no
  Image formats:
    GIF .................. yes (plugin, using bundled copy)
    JPEG ................. yes (plugin, using bundled copy)
    PNG .................. yes (in QtGui, using bundled copy)
  Glib ................... no
  GStreamer .............. no
  GTK theme .............. no
  Large File ............. yes
  libudev ................ no
  Networking:
    getaddrinfo .......... yes
    getifaddrs ........... yes
    IPv6 ifname .......... yes
    OpenSSL .............. no
  NIS .................... yes
  OpenGL ................. yes (OpenGL ES 2.x)
  OpenVG ................. no
  PCRE ................... yes (bundled copy)
  pkg-config ............. no
  PulseAudio ............. no
  QPA backends:
    DirectFB ............. no
    EGLFS ................ yes
    KMS .................. no
    LinuxFB .............. yes
    XCB .................. no
  Session management ..... yes
  SQL drivers:
    DB2 .................. no
    InterBase ............ no
    MySQL ................ no
    OCI .................. no
    ODBC ................. no
    PostgreSQL ........... no
    SQLite 2 ............. no
    SQLite ............... yes (plugin, using bundled copy)
    TDS .................. no
  udev ................... no
  xkbcommon .............. no
  zlib ................... yes (system library)

Now we can make  binaries with the following command. It may be useful to use screen  as the compilation took about 2 days at my RPi. By using screen you can exit the SSH connection without stopping all processes associated with that account. How to use screen  can be found here.

make

After some good night(s) of sleep you're now ready to install the binaries. From the qt5 directory run the install command.

sudo make install

In order to add the newly installed QT libraries available to the applications the next lines need to be added to your bashrc (which is executed whenever you log in to the raspberry pi with this username).

Make sure you test the QT folder name because it may have an other name (due to a different version for example).

nano .bashrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/Qt-5.2.0/lib/
export PATH=$PATH:/usr/local/Qt-5.2.0/bin

Execute the bashrc.

source .bashrc

And test if the new binaries are found.

which qmake

Which should output something like the following.

/usr/local/Qt-5.2.0/bin/qmake

Now we can test an application.

cp -r qt5/qtbase/examples/opengl/paintedwindow ~/
cd paintedwindow /
qmake
make
./paintedwindow

Success! You should now see an ellipse with "Hello" in it at the screen.

References:

http://qt-project.org/wiki/Building_Qt_5_from_Git

http://www.rackaid.com/resources/linux-screen-tutorial-and-how-to/

http://qt-project.org/wiki/Native_Build_of_Qt5_on_a_Raspberry_Pi

4 Comments

  1. I see you don't use the power of social websites like pinterest and facebook on your site.
    You can get big traffic from social sites on autopilot using one useful app,
    for more info search in google for:
    Alufi's Social Automation

  2. Hi,

    Have you tested QML examples on Raspberry Pi using TFT LCD?
    I've facing with some difficulties regarding to following issue:

    ./qml-rspi -platform linuxfb:fb=/dev/fb1:size=120x120
    QML debugging is enabled. Only use this in a safe environment.
    This plugin does not support createPlatformOpenGLContext!
    Failed to create OpenGL context for format QSurfaceFormat(version 2.0, options QFlags(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples -1, swapBehavior 2, swapInterval 1, profile 0)

    /dev/fb1 is trivial framebuffer driver (not supporting OPENGL whatsoever)

    1. That last bit is the telling part. if the fb driver for the device doesn't support openGL then you need to use linuxFB instead of EGLFS. This will force software only. Is this an Adafruit that's connected to the GPIO pins? If so, it's bypassing the GPU completely, so that's why you can't use EGLFS.

Leave a Reply to BK Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.