Qt Creator Cross Compiling Environment for Raspberry Pi3 with QtRpi


Update (June 2, 2018):
If you are using Raspbian Stretch, please check this post. The steps below are for Raspbian Jessie.


This is the steps how I created Qt Creator cross compiling environment on Ubuntu PC for Raspberry Pi 3 by using QtRpi. Thanks to QtRpi, it’s pretty straightforward. I followed the official site and its GitHub page. The purpose of this post is mostly for myself, to reproduce the steps in future (on other PCs or when I need to reinstall, etc).

 

Here is the list of contents of this post.

Contents
– Assumptions
– Steps
1. Preparation
2. Install Qt
3. Deploy Qt to Raspberry Pi
4. Qt Creator Configuration
5. Verify Cross Compiling Environment
– Troubleshoot
– Reference

 

Assumptions
Here are some assumptions before starting the steps:

– Ubuntu Linux running on host PC
– Raspbian running on the target Raspberry Pi 3
– Qt Creator running on host PC
– SSH access from host PC to target Raspberry Pi

In the steps below, I used following:

Ubuntu 16.04 as host
Raspbian Jessie (2017-07-05) running on Raspberry Pi 3 as target
Qt Creator 4.3.1 running on host

 

Steps
1. Preparation
1-1. Install dependencies

1-2. Configure environment variables
In my case, the environment variables are below since Qt version is 5.7.0 and target device is Raspberry Pi 3. In case you use different version or device, click here and see “2. Configure your environment variables” for other options.

Also, set your target’s IP address.

1-3. Password less SSH login
Generate SSH key and copy it to the target so that you can log in without requiring a password.

Just press enter when you asked about pass phrase.  Then, copy the key by typing:

 

2. Install Qt
The beauty of QtRpi is that scripts will take care of all the installation and deployment.

2-1. First, clone QtRpi from GitHub.

2-2. Then run “init-qtrpi-minimal.sh” script. This will take a while.

 

3. Deploy Qt to Raspberry Pi
3-1. Run “./deploy-qtrpi.sh” to deploy Qt

3-2. This step is a workaround for font display. (see troubleshoot section for detail.)
3-2-1. Login to Raspberry Pi.

3-2-2. Copy font files.

 

4. Qt Creator Configuration
To cross-compile and deploy from Qt Creator SDK, some configurations are required.

4-1. Device Configuration
4-1-1. Launch Qt Creator on host.
4-1-2. Navigate to “Tools” > “Options…”
4-1-3. In Options window, select “Devices” from left side bar.
4-1-4. Select “Add…”
4-1-5. Double click on “Generic Linux Device”

4-1-6. Enter information below into “New Generic Linux Device Configuration Setup” window.
Configuration name : Rpi 3
IP address : 192.168.0.5
Username : pi
Authentication type : Key

4-1-7. Click on “Next”, Then “Finish”. Then, it will automatically start “Device Test”.
4-1-8. Click “Close” to close “Device Test” window.
4-1-9. Click “Apply” on “Options” window (just in case?)

4-2. Debuggers
4-2-1. In Options window, select “Build & Run” from left side bar.
4-2-2. Click on “Debuggers” tab
4-2-3. Click on “Add” button
4-2-4. Put information below:
Name: GDB multiarch
Path : /usr/bin/gdb-multiarch

4-2-5. Click on “Apply”

4-3. Compilers
4-3-1. Click on “Compilers” tab
4-3-2. Navigate to “Add” > “GCC” > “C”
4-3-3. Enter information below:
Name: GCC rpi
Compiler Path: /opt/qtrpi/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/bin/gcc

4-3-4. Click on “Apply” button
4-3-5. Navigate to “Add” > “GCC” > “C++”
4-3-6. Enter information below:
Name :G++ rpi
Compiler Path:/opt/qtrpi/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/bin/g++

4-3-7. Click on “Apply” button

4-4. Qt Versions
4-4-1. Click on “Qt Versions” tab
4-4-2. Click on “Add…”
4-4-3. Navigate qmake path to “/opt/qtrpi/raspi/qt5/bin/qmake”
4-4-4. Enter “Qt rpi %{Qt:Version}” as “Version name”.

4-4-5. Click on “Apply” button

4-5. Kits
4-5-1. Click on “Kits” tab
4-5-2. Click on “Add” button
4-5-3. Enter (or select) information below:
Name : Rpi 3
Device Type: Generic Linux Device
Sysroot : /opt/qtrpi/raspbian/sysroot
Compiler: C: GCC rpi
Compiler: C++: G++ rpi
Debugger : GDB multiarch
Qt Version : Qt rpi 5.7.0

4-5-4. Click on “Apply” button, then “OK”.

 

5. Verify Cross Compiling Environment
Let’s check if everything is OK by building a sample project on host and executing it on RPi.

5-1. “File” > “New File or Project”
5-2. “Application” > “Qt Qucick Controls 2 Application”, then click on “Choose…” button.
5-3. Enter project name and click on “Next”.
5-4. Click on “Next” on “Define Build System” and “Define Project Details”.
5-5. Check on “Rpi 3” on “Kit Selection”.
5-6. Click on “Finish” button on “Project Management”.
5-7. Open .pro file from project tree.
5-8. Add two lines below at the end of the file and save it.

5-9. Select “Projects” icon on left side bar.
5-10. Click on “Rpi 3” under “Build & Run”.
5-11. Click on “Run” icon on the left side bar.

 

Troubleshoot
Originally, I’ve added the following environment variables to ~/.bashrc on Raspberry Pi after deploying Qt to Raspberry Pi based on video on official site.

However, when I run a program from Qt Creator on host PC, it seems that those variables are not set and no font is displayed on the application window. (getting below messages in “Application Output” on Qt Creator.) If I launch the same application from Raspberry Pi’s console, the issue doesn’t happen.

I’ve not been able to figure out the cause but found a workaround (step 3-2 above).

 

Reference
– QtRpi FAQ
http://www.qtrpi.com/faq#howtohttps://github.com/neuronalmotion/qtrpiinstall

– GitHub
https://github.com/neuronalmotion/qtrpi

 

 

Sponsor Link

Leave a Reply

Your email address will not be published. Required fields are marked *