Qt 5 development for Raspberry pi

If You want to build Qt5 development environmet for raspberry pi then you are in the right place. In this short tutorial you can build your Qt5 for raspberry pi. I used ubuntu-18.04-desktop-amd64 and rasp image is 2018-06-27-raspbian-stretch. For old images something can be different. If you have any trouble, then let me know I can help you.

Qt is a framework. What is framework ? Framework is a platform which includes several tools that makes your life easier. For example GUI libraries of Qt. They are best for me. One much more thing: you develop applications with C++ in Qt. ( Qt is cute not quti )

You can develop Qt applications for different hardware architectures. For raspberry pi we create a virtual machine ( host ) and we compile our projecst crossly. I just try to say we must make a cross compilation. As it is obvious our host hardware is (most probably) intel but the raspberry pi is ARM. They are totally different. Like white and black or Brad and Angelina. So to make understandable (?) what we do in intel, we cross compile our code then it will be ok for Rasp. To do that we need some toolchains that we will install in our virtual machine.

First thing first, lets create a virtual machine with virtual box. You can download virtual box from here https://www.virtualbox.org/wiki/Downloads

Then follow instruction in the video. Give about 30 GB space , it is enough. Then open it. Before go raspberry pi, be sure that , you supply the raspberry pi 5V 2.1A power source or much current. If you suppy it from your computer or you phone charger , then you will waste your hours in the next. If rasp is connected to the HDMI and you see the yellow lightning figure for a long time then you will have a power problem. If you have a problems with power do not go further ! Power be with you ! )

Now go to raspberry pi. Make it ssh available, ( create a directory which name is ssh in the boot directory with cmd.exe) log in with ssh. With putty ( you can use different serial terminal/emulator ) log in, User name is pi, passwd raspberry. Now change the root passwd and enable to login as a root.

sudo nano /etc/ssh/sshd_config

find the line PermitRootLogin and make it comment out.

then say yes

PermitRootLogin yes

to out ctrl -x and push the y

then give root password.

sudo passwd root
(mine is 1234)
sudo reboot

login as a root. User name is “root” and paswwd is “what you give”

Then,

nano /etc/apt/sources.list
uncomment the last line. apt-get update
apt-get dist-upgrade
reboot
rpi-update
reboot
-be sure rpi update work, try rpi-update again
*** Your firmware is already up to date – OKAY
sudo apt-get build-dep qt5-qmake
sudo apt-get build-dep libqt5webengine-data
sudo apt-get install libudev-dev libinput-dev libts-dev libxcb-xinerama0-dev libxcb-xinerama0
mkdir /usr/local/qt5pi
chown -R root:root /usr/local/qt5pi

That is ok for Raspberr pi. Do not power off it. We have a long night...


In ubuntu :
We create the vm open it, ( for network connect it via ethernet cable. I did it like that I did not have to make any additional configuration, I did not use Wifi. Create a good network with cables between your raspberry pi and computer. )

sudo passwd root

su

apt-get update

apt-get -y upgrade

apt-get install gcc git bison python gperf pkg-config

sudo mkdir /opt/qt5pi

sudo chown 1000:1000 /opt/qt5pi

cd /opt/qt5pi

git clone https://github.com/raspberrypi/tools

nano ~/.bashrc - it keep to long

export PATH=$PATH:/opt/qt5pi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

reboot

wget http://download.qt.io/official_releases/qt/5.10/5.10.1/single/qt-everywhere-src-5.10.1.tar.xz

tar xf qt-everywhere-src-5.10.1.tar.xz
cp -R qt-everywhere-src-5.10.1/qtbase/mkspecs/linux-arm-gnueabi-g++ qt-everywhere-src-5.10.1/qtbase/mkspecs/linux-arm-gnueabihf-g++

sed -i -e 's/arm-linux-gnueabi-/arm-linux-gnueabihf-/g' qt-everywhere-src-5.10.1/qtbase/mkspecs/linux-arm-gnueabihf-g++/qmake.conf

mkdir sysroot sysroot/usr sysroot/opt

rsync -avz root@192.168.16.25:/lib sysroot

rsync -avz root@192.168.16.25:/usr/include sysroot/usr

rsync -avz root@192.168.16.25:/usr/lib sysroot/usr

rsync -avz root@192.168.16.25:/opt/vc sysroot/opt

mv sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0 sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.0.0_backup

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

mv sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0 sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.0.0_backup

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

ln -s sysroot/opt/vc/lib/libEGL.so sysroot/opt/vc/lib/libEGL.so.1

ln -s sysroot/opt/vc/lib/libGLESv2.so sysroot/opt/vc/lib/libGLESv2.so.2

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

chmod +x sysroot-relativelinks.py

./sysroot-relativelinks.py sysroot

check syncronized file again

rsync -avz root@192.168.16.25:/lib sysroot

rsync -avz root@192.168.16.25:/usr/include sysroot/usr

rsync -avz root@192.168.16.25:/usr/lib sysroot/usr

rsync -avz root@192.168.16.25:/opt/vc sysroot/opt

./sysroot-relativelinks.py sysroot

mkdir qt5build

cd qt5build

../qt-everywhere-src-5.10.1/configure -opengl es2 -device linux-rasp-pi3-g++ -device-option CROSS_COMPILE=arm-linux-gnueabihf- -sysroot /opt/qt5pi/sysroot -prefix /usr/local/qt5pi -opensource -confirm-license -skip qtscript -nomake examples -make libs -pkg-config -no-use-gold-linker -v


=> for raspberry pi 0 => -device linux-rasp-pi-g++

=> for raspberry pi 2 => -device linux-rasp-pi2-g++

=> for raspberry pi 3 => -device linux-rasp-pi3-g++

=> for raspberry pi 3 + vc4 driver => -device linux-rasp-pi3-vc4-g++

make -j4

make install

cd /opt/qt5pi

rsync -avz sysroot/usr/local/qt5pi root@192.168.16.25:/usr/local

--

install qt-creator

apt-get install qtcreator

Lets create simple Hello world console application. With qt-creator choose new console application.



Go to path where your pro file stays.
Call the qmake with command
/opt/qt5pi/sysroot/usr/local/qt5pi/bin/qmake
then hit enter after that you will see the Makefile . Check with the ls command
to create a executable binary just
make
As it seen with file untitled, it is for ARM not intel.
Send it to the raspberr pi with
scp untitled root@192.168.16.25:/home
Back to raspberry pi. Go to home. Then ./untitled.
Hello World.

28/06/2018