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.

then

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 192.168.1.144

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 https://github.com/raspberrypi/tools

mkdir sysroot sysroot/usr sysroot/opt
rsync -avz pi@192.168.1.144:/lib sysroot
rsync -avz pi@192.168.1.144:/usr/include sysroot/usr
rsync -avz pi@192.168.1.144:/usr/lib sysroot/usr
rsync -avz pi@192.168.1.144:/opt/vc sysroot/opt

cd ~/raspi

wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py

chmod +x sysroot-relativelinks.py

./sysroot-relativelinks.py sysroot

wget https://download.qt.io/official_releases/qt/5.9/5.9.1/qt-opensource-linux-x64-5.9.1.run

wget https://download.qt.io/official_releases/qt/5.9/5.9.1/single/qt-everywhere-opensource-src-5.9.1.tar.xz

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

make install

cd ~/raspi

rsync -avz qt5pi pi@192.168.1.144:/usr/local

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
~/raspi/qt5/bin/qmake
make
scp stickman pi@192.168.1.144:/home/pi

cd ~/raspi
cd qt-everywhere-opensource-src-5.9.1/qtbase/examples/opengl/qopenglwidget
~/raspi/qt5/bin/qmake
make
scp qopenglwidget pi@192.168.1.144:/home/pi

cd ~/raspi
cd qt-everywhere-opensource-src-5.9.1/qtconnectivity/examples/bluetooth/btscanner
~/raspi/qt5/bin/qmake
make
scp btscanner pi@192.168.1.144:/home/pi

 

Back on the Pi

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

echo /usr/local/qt5pi/lib | sudo tee /etc/ld.so.conf.d/qt5pi.conf

sudo ldconfig

sudo cp /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0 /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0.bak

sudo cp /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0 /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0.bak

sudo rm /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0 /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0

sudo ln -s /opt/vc/lib/libEGL.so /usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0

sudo ln -s /opt/vc/lib/libGLESv2.so /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0

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

cd ~/
wget http://sourceforge.net/projects/dejavu/files/dejavu/2.37/dejavu-fonts-ttf-2.37.tar.bz2

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_force_hotplug=1
hdmi_cvt=480 320 60
hdmi_group=2
hdmi_mode=87

Now do the following to get raspi2fb installed.

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


cd ~/
wget https://github.com/AndrewFromMelbourne/raspi2fb/archive/master.zip
unzip master.zip
cd raspi2fb-master

mkdir build
cd build
cmake ..
make

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

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)