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 B+ 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 B+
– 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
sudo apt-get install curl g++ gdb-multiarch git realpath unzip zip -y
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.
export QTRPI_QT_VERSION='5.7.0' export QTRPI_TARGET_DEVICE='linux-rpi3-g++'
Also, set your target’s IP address.
export QTRPI_TARGET_HOST='pi@192.168.0.5'
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.
ssh-keygen
Just press enter when you asked about pass phrase. Then, copy the key by typing:
ssh-copy-id $QTRPI_TARGET_HOST
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.
git clone https://github.com/neuronalmotion/qtrpi.git
2-2. Then run “init-qtrpi-minimal.sh” script. This will take a while.
cd qtrpi ./init-qtrpi-minimal.sh
3. Deploy Qt to Raspberry Pi
3-1. Run “./deploy-qtrpi.sh” to deploy Qt
./deploy-qtrpi.sh --prepare-rpi
3-2. This step is a workaround for font display. (see troubleshoot section for detail.)
3-2-1. Login to Raspberry Pi.
ssh $QTRPI_TARGET_HOST
3-2-2. Copy font files.
cp -r /usr/share/fonts/truetype/dejavu /usr/local/qt5pi/lib/fonts
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.
target.path = /home/pi/ INSTALLS += target
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.
export QT_QPA_EGLFS_PHYSICAL_WIDTH=528 export QT_QPA_EGLFS_PHYSICAL_HEIGHT=295 export QT_QPA_FONTDIR=/usr/share/fonts/truetype/dejavu/
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.
QML debugging is enabled. Only use this in a safe environment. Unable to query physical screen size, defaulting to 100 dpi. To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters). QFontDatabase: Cannot find font directory /usr/local/qt5pi/lib/fonts. Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.
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
http://www.qtrpi.com seems unavailable. What to do in this case?
Sorry for my delayed response. It seems the server is working now. If not, you can follow RaspberryPi2EGLFS and Configuring Qt Creator for the Raspberry Pi.