Skip to content
Jason Charney edited this page Mar 26, 2016 · 15 revisions

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.

Installation

Installing Qt5 will be a LOOOOOOOOOOOOOOOOOONG process. Even longer if your Pi is an older model like the Pi B. What took two and a half days on the Pi B+, now takes about 10 hours on the Pi 2. I really want to automate this process.

Note: It hadn't dawned on my that sudo apt-get install qt5-qmake could have done the same thing, but I made it this far into the writing that I may as well do it the long way, especially if there's something GQRX wants that the binary Qt5 QMake doesn't have.

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

The list of prerequired packages got to be very long, so I wrote a script help download them all.

Even if you installed Ruby before hand, you'll still be asked to install some Ruby packages from the repo, which is OK.

$ cd ~/Software
$ git clone https://github.com/jrcharney/hacktop
$ cd hacktop/qt
$ ./aptget_install_qt5_pkgs.sh            # `chmod u+x aptget_install_qt5_pkgs.sh` if the script isn't executable.

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.

🔧 TODO: I may need to update this section. Things have changed.

Somewhere near line 815, you should see 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/configure 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.

# The original instructions wanted all the output to be sent to files using `&>`.
# It made more sense to pipe them through a tee command, that is `| tee`.
# Configure (This will take a few hours on the B+. Ditto for the Pi 2. At least a couple on the Pi 2.)
$ ./configure -v -opengl es2 -force-pkg-config -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 2>&1 | tee output_configure.log
# Make (This will take two days on the Pi B+.  Use `-j4` on the Pi 2 and it will be done in about five hours.)
$ make | tee output_make.log
# Make Install (This will take a few hours on the B+. About a half hour on the Pi 2.)
$ sudo make install | tee output_make_install.log
$ sudo bash -c 'echo "export PATH=/usr/local/qt5/bin:\$PATH" > /etc/profile.d/qt.sh'

TIP: You could heredoc that sudo bash -c line. It's more useful for multi line. Just be sure to escape your dollar signs like this \$, so bash won't process them. sudo bash -c 'cat > /etc/profile.d/qt.sh << EOF export PATH=/usr/local/qt5/bin:\$PATH EOF'

Let's wrap this up.

# Let's source this file.  If it doesn't add to your $PATH, you can open a new terminal.
$ source /etc/profile.d/qt.sh
# If that doesn't work. Open a new termnal.
# And to make sure everything works, let's ask where qmake is.
$ whereis qmake
qmake: /usr/bin/qmake /usr/local/qt5/bin/qmake
$ which qmake
/usr/local/qt5/bin/qmake                          # if you get /usr/bin/qmake, you've done something wrong.

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 ~/Software/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.

Checking the output files.

Once in a while you'll want to check in on those output files while compiling. You can do that as it is compiling, 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

Resources

See Also

  • Cmake
  • Make
  • [KDE](K Desktop Environment)
  • [Atom](Atom editor)
  • GQRX

Setup

  1. [Assemble the Hardware](Assemble the Hardware)
  2. [Install the Software](Install the Software)
  3. 🆙 [Setup your Raspberry Pi](Setup your Raspberry Pi)
  4. [Download the Missing Parts](Download the Missing Parts)

Typical Utilities

  • [Downloading and extracting with curl and tar](curl and tar)
  • [Browsing with ls and cat](ls and cat)
  • [Searching with grep and find](grep and find)
  • [Filtering with sed and awk](sed and awk)
  • [Piping with less, pv, and tee](less, pv, and tee)
  • Monitor your system with htop
  • Multiplex with tmux

Clone this wiki locally