• ...
  • SDK
  • Yocto
  • ...
  • ...
  • your first application
  • tools
  • ...
  • Qt: register
  • Qt: create project

Using Qt Creator#

To develop Qt application Qt Creator is probably the way to go IDE. But in order to cross compile the application for the target you want, it has to be configured first. Indeed the first time you want to use the Yocto SDK you will have to add a new development kit for your device adding:

  • a device

  • a development kit using:

    • a Qt version

    • a compiler

    • a debugger

    • a CMake

Then each project must be configured to use that new kit, and to use SimpleSwitch™ commands to build, deploy and run the application.

These 2 configuration steps could be done thanks to 2 scripts: - qtcreator-kit-configurator - qtcreator-project-configurator

In order to use the scripts to configure Qt Creator please refer to Option 1: configure Qt Creator using scripts. Naturally it is possible to configure Qt Creator manually, in that case please refer to Option 2: configure Qt Creator manually.

Source Yocto SDK environment

The Yocto SDK environment must be sourced to call the configurator scripts and to start Qt Creator. So you can start Qt Creator thanks to a terminal doing:

. /opt/sc/0.1.0/sm2s-imx8plus/environment-setup-cortexa53-crypto-simplecoredistro-linux
qtcreator

Option 1: configure Qt Creator using scripts#

Adding a kit and a device using the script#

The script to add a new device and kit is qtcreator-kit-configurator. With that tools three arguments should be used:

  • -a to choose the address IP of the device.

  • -c to select the path to the Qt Creator configuration directory.

  • -n to choose the name of the new kit.

So for example if:

  • you had installed Qt Creator from the Ubuntu deb package, the configuration path should be ~/.config/QtProject/qtcreator/.

  • the IP address of the target is 192.168.0.46

  • the SDK is made for an sm2s-imx8plus

You could just do:

  • Qt6 commercial
  • Qt6 community edition
    SIMPLESWITCH_TEMPLATE=qt6commercial qtcreator-kit-configurator -a 192.168.0.46 -c ~/.config/QtProject/qtcreator/ -n sm2s-imx8plus-kit
    ## On your computer run
    qtcreator-kit-configurator -a 192.168.0.46 -c ~/.config/QtProject/qtcreator/ -n sm2s-imx8plus-kit

Configure a project using the script#

Note

Only projects using Qmake build system can be configured by the script for the moment.

The script to configure the project is qtcreator-project-configurator. With that script, 2 arguments are mandatory:

  • -n to choose the kit name for which the script will configure the project.

  • -p to choose the path to the project configuration file (the pro.user one). This file is created the first time Qt Creator open the project.

If you already have a project but you have no .pro.user file, you could do:

  • Start Qt Creator.

  • Open the project created using the Qt Creator menu File, then Open File or Project... and browsing to the .pro file.

  • Make sure the Yocto toolchain kit is activated in the Build & Run section.

  • Close Qt Creator

If you have no project for the moment, you can create one thanks to Qt Creator:

  • Start Qt Creator.

  • Create the project using the Qt Creator menu File, then New File or Project... and answering the questions. The 2 import options is to choose qmake as Build System and to select the wanted Kits you configured previously.

  • Close Qt Creator

Now it is possible to call qtcreator-project-configurator. For example if:

  • the Qt kit is called sm2s-imx8plus-kit

  • the path to the project configuration file is ~/helloworld/helloworld/helloworld.pro.user (file which should have been created the first time you open the project with Qt Creator).

You could do:

  • Qt6 commercial
  • Qt6 community edition
    ## On your computer run
    SIMPLESWITCH_TEMPLATE=qt6commercial qtcreator-project-configurator -n sm2s-imx8plus-kit -p ~/helloworld/helloworld/helloworld.pro.user
    ## On your computer run
    qtcreator-project-configurator -n sm2s-imx8plus-kit -p ~/helloworld/helloworld/helloworld.pro.user

Select the Kit, build mode and run configuration#

The last step before compiling and deploying the SimpleSwitch™ package is to select the Kit, the build mode and the run configuration. Thanks to the menu Build then Open Build and Run Kit Selector.., you can then select them. The two mains set you should use are:

  • the debug mode

    • using the kit you created previously

    • Debug build mode

    • the debug run configuration you created (the one where you set the environment variable)

    • launching the application thanks to Start debugging of startup project.

  • the release mode

    • using the kit you created previously

    • Release build mode

    • the release run configuration you created (the one where you set the alternate executable command)

    • launching the application thanks to Run

../../../../../../_images/qt-creator-selector.png

Option 2: configure Qt Creator manually#

Adding a kit and a device manually#

Depending on your Qt Creator version, the tabs could not be organized exactly the same way as in the following documentation.

Add a device#

  • Click on the Tools menu then Options....

  • Select Devices in the left panel.

  • Click on Add, choose Generic Linux Device, then click on Start Wizard.

  • Enter a name for your device, the IP address of the board, and use root as username.

  • Continue and check that the Device Test is able to connect to your board.

  • Finally add in GDB server executable the value /tmp/qtcreator-gdbserver.sh. This script will be created during the deployment by simpleswitch-update-qtcreator-gdbserver.

../../../../../../_images/device.png

Add a Qt version#

  • Click on the Tools menu then Options....

  • Select Kits in the left panel.

  • Click on Qt Versions tab.

  • Click on Add and browse to find the qmake executable found in the Yocto SDK. If you didn’t change the default installation path it should be:

/opt/sc/0.1.0/sm2s-imx8plus/sysroots/x86_64-simplecoredistrosdk-linux/usr/bin/qmake
  • Adapt the name of the version.

../../../../../../_images/qt_version.png

Add a Compiler#

  • Click on the Tools menu then Options....

  • Select Kits in the left panel.

  • Click on Compilers tab.

  • Click on Add, then choose GCC and finally choose C.

  • Adapt the name of the compiler.

  • Browse to find the gcc executable found in the Yocto SDK. If you didn’t change the default installation path it should be:

/opt/sc/0.1.0/sm2s-imx8plus/sysroots/x86_64-simplecoredistrosdk-linux/usr/bin/aarch64-simplecoredistro-linux/aarch64-simplecoredistro-linux-gcc
  • Repeat the process adding a GCC compiler for the C++ choosing:

/opt/sc/0.1.0/sm2s-imx8plus/sysroots/x86_64-simplecoredistrosdk-linux/usr/bin/aarch64-simplecoredistro-linux/aarch64-simplecoredistro-linux-g++
../../../../../../_images/compiler.png

Add a Debugger#

  • Click on the Tools menu then Options....

  • Select Kits in the left panel.

  • Click on Debuggers tab.

  • Click on Add.

  • Adapt the name of the debugger.

  • Browse to find the gdb executable found in the Yocto SDK. If you didn’t change the default installation path it should be:

/opt/sc/0.1.0/sm2s-imx8plus/sysroots/x86_64-simplecoredistrosdk-linux/usr/bin/aarch64-simplecoredistro-linux/aarch64-simplecoredistro-linux-gdb
../../../../../../_images/debugger.png

Add CMake#

  • Click on the Tools menu then Options....

  • Select Kits in the left panel.

  • Click on CMake tab.

  • Click on Add.

  • Adapt the name of the CMake.

  • Browse to find the cmake executable found in the Yocto SDK. If you didn’t change the default installation path it should be:

/opt/sc/0.1.0/sm2s-imx8plus/sysroots/x86_64-simplecoredistrosdk-linux/usr/bin/cmake
../../../../../../_images/cmake.png

Add a Kit#

  • Click on the Tools menu then Options....

  • Select Kits in the left panel.

  • Click on Kits tab.

  • Click on Add.

  • Adapt the name of the Kit.

  • As Device type choose Generic Linux Device

  • As Device, Compiler, Debugger, Qt version and CMake Tool choose the ones you created previously.

  • As Sysroot browse to find the sysroot of the target in the Yocto SDK. If you didn’t change the default installation path it should be:

/opt/sc/0.1.0/sm2s-imx8plus/sysroots/cortexa53-crypto-simplecoredistro-linux/
  • As Qt mkspec add the mkspec of the target in the Yocto SDK. If you didn’t change the default installation path it should be:

/opt/sc/0.1.0/sm2s-imx8plus/sysroots/cortexa53-crypto-simplecoredistro-linux/usr/lib/mkspecs/linux-oe-g++
../../../../../../_images/kit.png

Configure a project manually#

If you already have a project open it using the menu File, then Open File or Project... and browsing to the .pro file of the project. Else create a project using the menu File, then New File or Project... and answering the questions. The 2 import options is to choose qmake as Build System and to select the wanted Kits you configured previously. Then:

  • Select the Projects configuration tab (on the left of the screen).

  • Make sure the Yocto toolchain kit is activated in the Build & Run section and is configured to run on the device you added (Run / Run section)

  • In the Build / Build Steps section, disable Make step (DON’T remove it).

  • In this same section, add a new Custom Process Steps to create the SimpleSwitch™ package:

  • QT6 commercial
  • QT6 community editon
  • Command: simpleswitch-generate-package

  • Arguments: --name %{ActiveProject:Name} --makefile-dir %{buildDir} --template qt6commercial --allow-update --startup-command /opt/%{ActiveProject:Name}/bin/%{ActiveProject:Name}

  • Working directory: %{buildDir}/..

  • Command: simpleswitch-generate-package

  • Arguments: --name %{ActiveProject:Name} --makefile-dir %{buildDir} --template qt6 --allow-update --startup-command /opt/%{ActiveProject:Name}/bin/%{ActiveProject:Name}

  • Working directory: %{buildDir}/..

../../../../../../_images/qt-creator-build.png
  • In the Run / Deployment section, disable or remove the Kill current application instance and the Deploy files via rsync steps.

  • In this same section, add a new Custom Process Steps to deploy the SimpleSwitch™ package:

    • Command: simpleswitch-deploy-package

    • Arguments: %{ActiveProject:Name} %{Device:HostAddress} --allow-update

    • Working directory: %{buildDir}/..

  • And add another Custom Process Steps to update the GDB helper script used during debug. As Qt Creator only allows to set a single GDB server path for all projects, this script needs to be updated on each deploy:

    • Command: simpleswitch-update-qtcreator-gdbserver

    • Arguments: %{ActiveProject:Name} %{Device:HostAddress}

    • Working directory: %{buildDir}/..

../../../../../../_images/qt-creator-deploy.png
  • In the Run / Run section, you will need to set two configurations. First of all, Clone... the default run configuration in order to create the first one which will be used for debugging.

../../../../../../_images/qt-creator-clone-debug.png
  • Modify the newly run configuration to add the following environment variables in Run / Environment section.

    • QT_QPA_PLATFORM must be set to wayland.

    • XDG_RUNTIME_DIR must be set to the path set on target, /run/user/0.

../../../../../../_images/qt-creator-env-debug.png
  • The second one will be used when running the application. Switch back to the default run configuration and again click on Clone...

../../../../../../_images/qt-creator-clone.png
  • Modified this new run configuration to set:

    • Alternate exectuable on device to systemctl with Use this command instead selected.

    • Command line arguments to start simpleswitch-app@%{ActiveProject:Name}.

../../../../../../_images/qt-creator-env.png

The project has been configured manually as would have been done by the script. Now you can refer to the section Select the Kit, build mode and run configuration to then be able to compile and deploy the SimpleSwitch™ package.