Cross compile Qt for Raspberry Pi (OpenGL)
 Page :   [ 1 ]    [ 2 ]    [ 3 ]  


On your Pi

sudo pico -w /etc/apt/sources.list

and uncomment the "deb-src" line.


sudo apt-get update

If you are interested in Bluetooth support then:

sudo apt-get install bluetooth bluez libbluetooth-dev bluez-tools

Now continue on with

sudo apt-get build-dep qt4-x11
sudo apt-get build-dep libqt5gui5
sudo apt-get install libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0

sudo mkdir /usr/local/qt5pi
sudo chown pi:pi /usr/local/qt5pi


On Kubuntu 16.04.2 Virtual Machine (64 bit)


Note: I set a static DHCP lease for the Raspberry Pi with an IP address of

Building the cross compiled Qt and getting it to the Pi.


sudo apt-get update

sudo apt-get upgrade


Then do all this:

sudo apt-get install libgl1-mesa-dev

sudo apt-get install git

mkdir ~/raspi
cd ~/raspi
git clone

mkdir sysroot sysroot/usr sysroot/opt
rsync -avz pi@ sysroot
rsync -avz pi@ sysroot/usr
rsync -avz pi@ sysroot/usr
rsync -avz pi@ sysroot/opt

cd ~/raspi


chmod +x

./ sysroot



tar xJf qt-everywhere-opensource-src-5.9.1.tar.xz

cd qt-everywhere-opensource-src-5.9.1

./configure -release -opengl es2 -device linux-rasp-pi2-g++ -device-option CROSS_COMPILE=~/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf- -sysroot ~/raspi/sysroot -opensource -confirm-license -prefix /usr/local/qt5pi -extprefix ~/raspi/qt5pi -hostprefix ~/raspi/qt5 -v -no-use-gold-linker -nomake examples -nomake tests


make install

cd ~/raspi

rsync -avz qt5pi pi@

Now to test building a couple example apps and transferring them to the Pi.

cd ~/raspi
cd qt-everywhere-opensource-src-5.9.1/qtbase/examples/widgets/animation/stickman
scp stickman pi@

cd ~/raspi
cd qt-everywhere-opensource-src-5.9.1/qtbase/examples/opengl/qopenglwidget
scp qopenglwidget pi@

cd ~/raspi
cd qt-everywhere-opensource-src-5.9.1/qtconnectivity/examples/bluetooth/btscanner
scp btscanner pi@


Back on the Pi

Do the following to make sure the Qt stuff works OK:

echo /usr/local/qt5pi/lib | sudo tee /etc/

sudo ldconfig

sudo cp /usr/lib/arm-linux-gnueabihf/ /usr/lib/arm-linux-gnueabihf/

sudo cp /usr/lib/arm-linux-gnueabihf/ /usr/lib/arm-linux-gnueabihf/

sudo rm /usr/lib/arm-linux-gnueabihf/ /usr/lib/arm-linux-gnueabihf/

sudo ln -s /opt/vc/lib/ /usr/lib/arm-linux-gnueabihf/

sudo ln -s /opt/vc/lib/ /usr/lib/arm-linux-gnueabihf/

Get some fonts onto the Pi so the apps don't complain there's no fonts!

cd ~/

tar xvjf dejavu-fonts-ttf-2.37.tar.bz2

mkdir /usr/local/qt5pi/lib/fonts

mv dejavu-fonts-ttf-2.37/ttf/*.ttf /usr/local/qt5pi/lib/fonts

Now to test one of these example apps (this one is not OpenGL)

~/stickman -platform linuxfb:fb=/dev/fb0

this should be displaying on the 3.5" TFT.

The qopenglwidget won't display on that TFT display.  it would display OK using the HDMI port so something is needed to copy that framebuffer to the framebuffer for the TFT.  I'm using something called "raspi2fb"

sudo pico -w /boot/config.txt

 and add this to the bottom of config.txt

hdmi_cvt=480 320 60

Now do the following to get raspi2fb installed.

sudo apt-get install libbsd-dev
sudo apt-get install cmake

cd ~/
cd raspi2fb-master

mkdir build
cd build
cmake ..

sudo make install

sudo cp ../raspi2fb@.service /etc/systemd/system/

sudo systemctl daemon-reload

sudo systemctl enable raspi2fb@0.service

sudo systemctl start raspi2fb@0


Rebooted the Pi before testing the qopenglwidget app.

cd ~/

If all went well you should see the example app running on the 3.5" display.


Also try running the bluetooth example if you want.  Just be sure to run it as root.

cd ~/
sudo ./btscanner

You should be able to scan for BT devices!


On the next page we install Qt Creator!




(Page 2 of 3)