C

Set up your Development Host

Qt for MCUs supports Linux and Windows host environments. The following subsections provide the setup information for these host platforms.

Prerequisites

Install the following prerequisites in addition to Qt for MCUs. You can install Qt for MCUs using the Qt online installer, which can be downloaded from your Qt account page.

  • CMake 3.21.1 or newer (you can install it using the Qt Online installer)
  • GNU Make

If building the desktop target in order to test the applications on the desktop:

  • GNU Compiler Collection v7.4.0 or newer
  • New Perl Compatible Regular Expression Library - 16 bit (libpcre2-16-0)

All these prerequisites can be installed using the following commands:

sudo apt update
sudo apt install build-essential cmake libpcre2-16-0
  • CMake 3.21.1 or newer (you can install it using the Qt Online installer)

If building the desktop target in order to test the applications on the desktop:

Qt Creator setup

The following instructions help you set up Qt Creator on the Linux and Windows platforms.

To develop for MCUs using the Qt Creator IDE, the MCU plugin is required. The Qt online installer enables it by default when you install the Qt for MCUs SDK.

To enable or disable the plugin, follow these instructions:

  1. Select Help > About Plugins and choose the MCU Support plugin from the list.
  2. Restart Qt Creator to apply changes

To build and run your application on MCUs, you must create a kit:

  1. Select Edit > Preferences > Devices > MCU
  2. If not already set, provide the path to the Qt for MCUs installation directory.
  3. Select a Target supported by the Qt for MCUs SDK. For example, Qt for MCUs 2.3 - Desktop 32bpp.
  4. In the Requirements section, ensure that the platform-specific requirements are met.
  5. Select Automatically create kits for all available targets on start to create kits automatically.

    Note: You could also manually create/remove kits using Create Kit and Remove Kit.

  6. Click Apply and restart Qt Creator if you choose to create kits automatically.

Note: The Automatically create kits for all available targets on start option is available from Qt Creator v4.14 onwards. On older versions of Qt Creator, you have to explictly create or remove kits using Create kit or Remove kit.

Command line setup

This page uses QUL_ROOT and QUL_TOOLS in command line examples as if they were set as environment variables. For example:

export QUL_ROOT=$HOME/Qt/QtMCUs/2.3
export QUL_TOOLS=$HOME/Qt/Tools/QtMCUs
set QUL_ROOT=C:\Qt\QtMCUs\2.3
set QUL_TOOLS=C:\Qt\Tools\QtMCUs

Setting up the project

To configure a project, run CMake from the command prompt. Navigate to your project directory and enter the following commands, which uses the %QUL_ROOT%\demos\thermo demo as an example.

cd $QUL_ROOT/demos/thermo
mkdir build_linuxqt
cd build_linuxqt
cmake .. -DQUL_PLATFORM=Qt -DQul_ROOT=$QUL_ROOT
cd %QUL_ROOT%\demos\thermo
mkdir build_winqt
cd build_winqt
cmake .. -DQUL_PLATFORM=Qt -DQUL_COMPILER_NAME=msvc -DQul_ROOT=%QUL_ROOT%

Note: You can choose between the MSVC (msvc) and MinGW (gnu) toolchains using the QUL_COMPILER_NAME CMake option.

If you pass the QUL_COMPILER_NAME=gnu CMake option to use the MinGW toolchain, ensure to choose either the Ninja or MinGW Makefiles generator explicitly, as shown below. This is required because CMake uses the Visual Studio Generators by default if Visual Studio is installed.

cmake .. -G "Ninja" -DQUL_PLATFORM=Qt -DQUL_COMPILER_NAME=gnu -DQul_ROOT=%QUL_ROOT%

These commands check for the prerequisites and configure your project.

Building

To build, use the following command:

cmake --build . --target thermo_big --config Release

Note: The prebuilt libraries for the Qt platform are available only for Debug and Release configurations. On Windows other build types might lead to linking errors.

Running the application

Once the thermostat application is built, try to running it:

./thermo_big

The thermo demo is built as a Qt application for Windows, so it requires the Qt runtime libraries in the PATH to run. Qt for MCUs provides all these necessary Qt libraries, which must be added to your PATH.

set PATH=%QUL_ROOT%\lib\msvc;%PATH%
set QT_QPA_PLATFORM_PLUGIN_PATH=%QUL_ROOT%\lib\msvc

Note: The Qt runtime libraries for the MinGW toolchain are installed into QUL_ROOT\lib\gnu.

Now that your PATH includes the necessary libraries, run the application:

%QUL_ROOT%\demos\thermo\build_winqt>Release\thermo_big.exe

Note: You can find the executable in the build directory when using the MinGW toolchain.

The Thermostat application window should look like this:

Visual Studio setup on Windows

Setting up the project

To configure the project, follow instructions in the Command line setup section.

Open the solution in Visual Studio

To work with your project using Microsoft Visual Studio, open the solution created by CMake from the build_winqt folder.

Now, you should see the solution tree structure.

As this is a Windows Qt project, it requires Qt's runtime libraries to run. To make them available for the built application, you must set the runtime environment. To do this:

  1. Right-click on your project and select Properties from the context menu.
  2. Click General > Debugging
  3. To Environment add the PATH and QT_QPA_PLATFORM_PLUGIN_PATH variables pointing to the directory containing the Qt libraries, which are installed into the lib\msvc directory of your QUL_ROOT. For example:
    PATH=%QUL_ROOT%\lib\msvc
    QT_QPA_PLATFORM_PLUGIN_PATH=%QUL_ROOT%\lib\msvc

After this step (assuming %QUL_ROOT% was set to C:\Qt\QtMCUs\2.3.0) the project properties window should look like this:

Build & run

Apply the changes, build the application, and run it. You should see on the screen the thermostat demo.

Available under certain Qt licenses.
Find out more.