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 Qt Online Installer, which can be downloaded from your Qt account page.

  • CMake 3.21.1 or newer (you can install it using 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 Qt Online Installer)

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

Note: On Linux, if you have installed gcc-12 without g++-12, the GCC headers in the include path lead to missing C++ headers ('cstdint' file not found) when running qmlinterfacegenerator. Either remove gcc-12 or install g++-12 to resolve this issue.

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. Qt Online Installer enables it by default when you install the Qt for MCUs SDK.

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

  1. Select Edit > Preferences > Devices > MCU.

    Note: If you cannot see the MCU tab, select Help > About Plugins, enable the McuSupport plugin, and restart Qt Creator to apply changes.

  2. If not already set, provide the path to the Qt for MCUs installation directory.

    {MCU preferences}

  3. Select a Target supported by the Qt for MCUs SDK. For example, Qt for MCUs 2.10.0 - 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 can also create/update kits manually using Create Kit and Update Kit.

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

Command line setup

QUL_ROOT and QUL_TOOLS are used in the command line examples below as if they were set as environment variables. For example:

export QUL_ROOT=$HOME/Qt/QtMCUs/2.10.0
export QUL_TOOLS=$HOME/Qt/Tools/QtMCUs
set QUL_ROOT=C:\Qt\QtMCUs\2.10.0
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.