-
Notifications
You must be signed in to change notification settings - Fork 1
Qt5 for Raspberry Pi
Qt is a User Interface tool kit used to build many software. Most notably the K Desktop Environment (a.k.a. KDE). For a while, Qt was owned by Finnish cellphone manufacture Nokia, until Microsoft bought Nokia and Qt became independent again.
Much like GNU Make and CMake, Qt comes with it's own software building too called qmake.
Until recently, it was difficult to explain how to build Qt5 for Raspberry Pi especially since it came with Qt4.
Firstly, a few notes about this installation process. When I did this, I was still using my Raspberry Pi B+. I haven't tried this with the Pi 2 yet.
Secondly, I highly recommend that for this installation, you break out the old Ethernet cable and hook your Pi up to your internet router when downloading Qt5. If something bad happens at the ./init-repository (which is the step that downloads all the important stuff), you will need to delete everything and start back at the git clone step, which is no fun considering the amount of squirrel power Raspberry Pis run on.
Thirdly, the ./init-repository, ./configure and sudo make install parts of the install will take a few hours, but the make part will take two days. Sure, you can cross-compile and get this done faster, but if you are like me and want everything done on one machine, you'll need to leave the pi running for a couple of days. Make sure that if you do a hacktop configureation that you don't close the lid or if you use a remote connection that the connection will stay up for that length of time.
Prerequired before doing this, update and upgrade your binaries, and insure that the following list of packages are installed. (Use the LXTerminal and copypasta everything.)
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install libfontconfig1-dev libdbus-1-dev libfreetype6-dev libudev-dev libicu-dev libsqlite3-dev libxslt1-dev libssl-dev libasound2-dev libavcodec-dev libavformat-dev libswscale-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev gstreamer-tools gstreamer0.10-plugins-good gstreamer0.10-plugins-bad libraspberrypi-dev libpulse-dev libx11-dev libglib2.0-dev libcups2-dev freetds-dev libsqlite0-dev libpq-dev libiodbc2-dev libmysqlclient-dev firebird-dev libpng12-dev libjpeg62-dev libgst-dev libxext-dev libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-sync0 libxcb-sync0-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-glx0-dev libxi-dev libdrm-dev
OK, with that out of the way, here we go.
cd ~/Software/
git clone git://code.qt.io/qt/qt5.git
cd qt5/
./init-repository # This will take a while. Mow the lawn.
vim qtbase/configure # This part is for the next step
Next, we need to edit the qtbase/configure. In the command mode of vim, type :/Qt_CFLAGS_DBUS then press enter to jump to the line that starts with Qt_CFLAGS_DBUS.
The part of the qtbase/configure file we want to edit will look something like this.
# flags for libdbus-1
QT_CFLAGS_DBUS=
QT_LIBS_DBUS=
# flags for Glib (X11 only)
QT_CFLAGS_GLIB=
QT_LIBS_GLIB=
# flags for GStreamer (X11 only)
QT_CFLAGS_GSTREAMER=
QT_LIBS_GSTREAMER=
It might not look exactly like that, but so as long as the lines for Qt_{CFLAGS|LIBS}_DBUS and Qt_{CFLAGS|LIBS}_GLIB are close by, that's definitely where we want to make our first edits to this file.
Change that file to look more like this
# flags for libdbus-1
QT_CFLAGS_DBUS="-I/usr/include/dbus-1.0/ -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include/"
QT_LIBS_DBUS=-ldbus-1
# flags for Glib (X11 only)
QT_CFLAGS_GLIB="-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/"
QT_LIBS_GLIB=-lglib-2.0
QT_CFLAGS_PULSEAUDIO="-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/"
QT_LIBS_PULSEAUDIO="-lpulse -lpulse-mainloop-glib"
# flags for GStreamer (X11 only)
QT_CFLAGS_GSTREAMER="-I/usr/include/gstreamer-0.10/ -I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-
gnueabihf/glib-2.0/include/ -I/usr/include/libxml2/"
QT_LIBS_GSTREAMER=
The other change to qtbase/config is to look for the QT_CFLAGS_FONTCONFIG section. (ESC then type :/QT_CFLAGS_FONTCONFIG then press enter). It should jump to the part of the file that looks kind of like this.
# auto-detect FontConfig support
if [ "$CFG_FONTCONFIG" != "no" ]; then
if [ -n "$PKG_CONFIG" ] && $PKG_CONFIG --exists fontconfig --exists freetype2 2>/dev/null; then
QT_CFLAGS_FONTCONFIG=`$PKG_CONFIG --cflags fontconfig --cflags freetype2 2>/dev/null`
QT_LIBS_FONTCONFIG=`$PKG_CONFIG --libs fontconfig --libs freetype2 2>/dev/null`
else
QT_CFLAGS_FONTCONFIG=
QT_LIBS_FONTCONFIG="-lfreetype -lfontconfig"
fi
...
Do you see the QT_CFLAGS_FONTCONFIG= in the else part of the statement? Change it to look like this.
...
else
QT_CFLAGS_FONTCONFIG=-I/usr/include/freetype2/
QT_LIBS_FONTCONFIG="-lfreetype -lfontconfig"
fi
...
Our work in that file is done. Press ESC, type :wq to save and close vim.
Normally, when we do the ./configure && make && sudo make install process, we do all that in one step. For this install process, we don't do that. In fact, in addition to doing each step separately, we will also write our output in each step to a separate file. I'll have some advice for checking in on the output files later, especially since this way will be very quiet instead of that verbose list of text you probably don't understand. Any errors can surely be Googled later. Any failures will likely be identified by how soon these processes get done, and they should not be done very soon. In fact, they are supposed to take a while.
# Configure (This will take a few hours)
./configure -v -opengl es2 -device linux-rasp-pi-g''+ -device-option CROSS_COMPILE=/usr/bin/ -opensource -confirm-license -optimized-qmake -reduce-exports -release -qt-pcre -make libs -prefix /usr/local/qt5 &> output
# Make (This will take two days)
make &> output_make
# Make Install (This will take a few hours)
sudo make install &> output_make_install
# Edit ~/.bashrc (this will be part of our next step)
vim ~/.bashrc
If you've made it this far, congratulations! You are just a few steps away from using qmake. You will need to edit the ~/.bashrc file by adding these lines at the bottom.
# Set up Qt5
# export LD_LIBRARY_PATH=/usr/local/qt5/lib/ # UPDATE: THIS DOES NOTHING! DON'T ADD IT! And every says "DON'T!"
export PATH="$PATH:/usr/local/qt5/bin"
Save and close vim and then run this command.
source ~/.bashrc
And to make sure everything works, let's ask where qmake is.
$ which qmake
/usr/local/qt5/bin/qmake
So how do we know that all of this works? Well, let's compile a demo that is included with this project in our ~/Sandbox folder.
cp -r ~/opt/qt5/qtbase/examples/opengl/cube ~/Sandbox
cd ~/Sandbox/cube
qmake
make
./cube
On that last step, you should see a dice face. Use your mouse to drag the shape any which way. Press CTRL+C to return.
You should be all set up to use Qt5 now. I'm using it to get GQRX running for my Software Defined Radio.
Once in a while you'll want to check in on those output files while compiling. You can do that as it is compling, just do it in another terminal window.
The simplest command for checking on things is tail. The tail command will return the last 10 lines. You'll definitely want to do this instead of using cat.
tail output
What about the output_make file? Often it will mix the file it working on with the arguments that are being used to compile each file. Sometimes it will use gcc, sometimes it will use g++, sometimes it will use make, or it will use one of those previous three with the /usr/bin/ path. As much as I would have liked to share a single answer to this, just using tail output_make is still better. However, gawk gives us something to work with.
tail output_make
tail output_make | awk -F" " '/^g[c+]+/{print $NF}'
tail output_make | awk -F" " '/^\/usr\/bin\/g[c+]+/{print $NF}'
You could also check the sizes of the files while they are working. Here's what I had when all three of these were done.
$ ls -lh output*
-rw-r--r-- 1 pi pi 136K Oct 5 16:53 output
-rw-r--r-- 1 pi pi 13M Oct 7 04:46 output_make
-rw-r--r-- 1 pi pi 919K Oct 7 07:54 output_make_install