Configure Qt Creator on Ubuntu 20 LTS for Cross-Compile

Introduction

This is a guide for configuring the Qt-Creator to use cross-compiled Qt libraries for the Raspberry Pi 4 and to create applications for the Raspberry.

Preconditions

Raspberry Pi OS Lite

Install Raspberry Pi OS Lite on a Raspberry Pi 4 or on a Raspberry Compute Module 4 as described in my blog post Installing Raspberry Pi OS on Raspberry Compute Module 4.

Qt 5.15.2 on Ubuntu 20 LTS

Configure Raspberry Pi OS Lite on a Raspberry Pi 4 or install Raspberry Pi OS on Raspberry Compute Module 4 as in my blog post and build the Qt libraries as in my blog post Qt 5.15 cross compile for Raspberry Compute Module 4 on Ubuntu 20 LTS.

Configuration Qt-Creator

You should have a working Qt creator installed on an Ubuntu 20. Instructions on how to do this can be found at Qt or in various forums or tutorials.
In addition, you should have created a Raspberry Pi 4 or a Raspberry Compute Module 4 with Raspberry Pi OS Lite and the corresponding Qt libraries, a cross-compiler and the cross-compiled libraries for the Raspberry Pi 4 as described in the prerequisites.
The paths used below for the different configurations correspond to the paths from the two previous blog posts.
My QtCreator version used is version 4.13.3.

Create Device

In the first step, we create a new device. To do this, call up "Options" in the menu under "Tools" and select "Devices" in the left column. Then use "Add" to create a new device "Generic Linux Device". Give the device a name - here RaspberryPi4-Qt-5.15 -, enter the IP address under "Host name" and typically enter "pi" under "Username" for the Raspberry.
Then you can use the "Test" button to test the connection to the Raspberry. If "Device test finished successfully." is not returned here, you have to check the settings and test whether the Raspberry is really reachable with these parameters.

QtCreator Device Configuration

### Configuring the Compiler In the second step, we need to define the paths for the C and C++ compilers. The settings for this can be found again in the menu "Tools -> Options" under "Kits -> Compilers". We use the compilers here that we downloaded with the cross-compiler "gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf". Add -> GCC -> C" and "Add -> GCC -> C++" to add two new configurations. For C, in the "tools" directory, "gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc" and for C++ "gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++". Assign one name at a time and this setting is ready.
QtCreator Compiler Configuration

### Create Qt version In the third step, we need the cross-compiled qmake file from the previous blog post. The settings for this can be found again in the menu "Tools -> Options" under "Kits -> Qt Versions". Add a new configuration again with "Add" and select the qmake file from the directory "qt5.15/bin/qmake" with the "Browse" button.
QtCreator Version Configuration

### Create a kit The final step is to merge the newly added configurations into a new kit. The settings for this can be found in the menu "Tools -> Options" under "Kits -> Kits". Add a new configuration again with "Add" and at
  • Name: assign your own name (this will later be used to select the device under the "Project" settings)
  • Device type: "Generic Linux Device"
  • Device: select the newly created device
  • Sysroot: select the sysroot directory created in the previous blog post
  • Compiler: select the two newly created compilers
  • Qt version: select the newly created Qt version
    QtCreator Kit Configuration

    ### Project Settings The newly created kit can now be selected and assigned immediately when creating a new project or added to an existing project.
    QtCreator Project Configuration