Building Qt for QNX | Qt 6.11
Description: Describes required packages and necessary configuration for building.

- Qt 6.11
- Product information
- Supported Platforms
- Qt for QNX
- Building Qt for QNX
- Qt 6.11.0 Reference Documentation

Qt for QNX Support ◦ Runtime Target Requirements

# Building Qt for QNX

## Setting up QNX SDP

Building Qt 6 requires downloading and installing a QNX SDP from the QNX website.

Note: A suitable license is required. Contact QNX for more information.

Note: Don't add experimental Wayland packages from QNX Software Center to your QNX SDP 8.0 installation. They are not needed to build Qt but can cause a header conflict when configuring a Qt build.

The compiler and other parts of the toolchain are provided in the SDP packages. Initialize your build environment by running the QNX setup script from your SDP installation folder in a terminal as follows:

     source qnxsdp-env.sh

Or run qnxsdp-env.bat on the Windows command shell.

## Host build

A host build of Qt needs to be available to cross-compile Qt. This is because, during the build, certain tools (such as `moc`, `rcc`, `qmlcachegen`, and `qsb`) are invoked from the host build. You have two options:

- Building Qt Sources for the host or
- installing host build using Qt Online Installer.

## Creating a toolchain file for QNX

To cross-compile a project with CMake, you need a toolchain file. This CMake language file sets the correct values for the platform name, compiler/linker, and many other toolchain-specific things. For reference, you can find toolchain files used in CI from source package coin/provisioning/common/shared/cmake_toolchain_files

     set(CMAKE_SYSTEM_NAME QNX)
     set(CMAKE_SYSTEM_PROCESSOR armle-v7)
     set(arch gcc_ntoarmv7le)

     set(CMAKE_C_COMPILER qcc)
     set(CMAKE_C_COMPILER_TARGET ${arch})
     set(CMAKE_CXX_COMPILER q++)
     set(CMAKE_CXX_COMPILER_TARGET ${arch})

     set(CMAKE_FIND_ROOT_PATH $ENV{QNX_TARGET};$ENV{QNX_TARGET}/${CMAKE_SYSTEM_PROCESSOR})

     set(CMAKE_SYSROOT $ENV{QNX_TARGET})

The example file is for `armv7le`. The other possibilities are `aarch64le` and `x86_64`, depending on your target architecture.

Note: Cmake doesn't pass STRIP, AR, RANLIB and NM variables correctly on QNX, so if used, they need to be specified separately in a toolchain file.

## Configuring and building Qt for QNX

To configure and build Qt for QNX, you need the following:

- Tools for building Qt, as described in Building Qt Sources, are in place and functional for your host platform.
- The toolchain file, in this example `$HOME/qnx.cmake`.
- The Qt source code checked out or installed, in this example under `$HOME/qt`.
- Host build of Qt, in this example `$HOME/qt-host`.
- Prefix for the Qt build installation location on the local system, in this example `$HOME/qnx-install`.
- Prefix for the Qt build deployment location on the target device, in this example `/qt`.

After creating and switching to the `build` directory, run the following:

     $HOME/qt/configure -nomake examples -nomake tests \
     -qt-host-path $HOME/qt-host \
     -extprefix $HOME/qnx-install \
     -prefix /qt \
     -- -DCMAKE_TOOLCHAIN_FILE=$HOME/qnx.cmake  \
     -DCMAKE_SYSTEM_VERSION=710  \
     $HOME/qt

Since Qt 6, the configure tool is a wrapper around CMake and in practice, this configure command is equivalent to the following direct CMake call:

     cmake -GNinja -DQT_BUILD_EXAMPLES=OFF -DQT_BUILD_TESTS=OFF \
     -DQT_HOST_PATH=$HOME/qt-host \
     -DCMAKE_STAGING_PREFIX=$HOME/qnx-install \
     -DCMAKE_INSTALL_PREFIX=/qt \
     -DCMAKE_TOOLCHAIN_FILE=$HOME/qnx.cmake  \
     -DCMAKE_SYSTEM_VERSION=710  \
     $HOME/qt

Choose the value of CMAKE_SYSTEM_VERSION based on your QNX SDP version:

- 710 for QNX SDP 7.1
- 800 for QNX SDP 8.0

If you are working only with one QNX version, you can also define CMAKE_SYSTEM_VERSION in your toolchain file.

Note: When building on Windows, PCH (Precompiled Headers) needs to be explicitly disabled, as enabling it causes the QNX compiler to crash. To disable PCH, use the configuration option `-no-pch`.

Note: If using QNX SDP 8.0, skip unsupported and their dependent modules using configuration options `-skip qtmultimedia -skip qtspeech -skip qtremoteobjects -skip qtinterfaceframework`.

Once the configuration completes without errors, build Qt by running the following:

     cmake --build . --parallel

Note: QNX compiler may require more memory than the compiler used for host build. Use `--parallel <numOfProcesses>` to limit the maximum number of concurrent processes when building.

Once built, run the following:

     cmake --install .

This installs the results to `$HOME/qnx-install`. From there you can deploy the Qt build to target device using Qt Creator, scp directly or some another method. The `-prefix` configuration parameter (/qt in the example) defines the deployment location on target device.

## Building applications for the target device

When you have finished the Qt build and it's installed in the staging location, you can build examples or applications.

With CMake, use the generated `qt-cmake` script in the bin directory of the staging location (`$HOME/qnx-install` in the example) to configure the application build and then run ninja. For example:

     $HOME/qnx-install/bin/qt-cmake .
     cmake --build .

You can then deploy the resulting application binary to the device. Using the `qt-cmake` helper script is convenient because the script ensures the toolchain file that was used for building Qt is loaded, so there is no need to repeatedly specify it for each application.

If you are using a Qt installation that has not been built on your machine, `qt-cmake` needs to know the location of the CMake toolchain file for the target platform.

In such a case, instruct `qt-cmake` to chain load a custom toolchain file by setting the `QT_CHAINLOAD_TOOLCHAIN_FILE` variable as follows:

     $HOME/qnx-install/bin/qt-cmake -DQT_CHAINLOAD_TOOLCHAIN_FILE=$HOME/qnx.cmake .

When building applications in Qt Creator using Qt installation that has not been built in your machine, the `CMAKE_TOOLCHAIN_FILE` variable, pointing to local toolchain file, needs to be added to kit configuration (Edit > Preferences > Kits).

For more information on connecting and adding kits for QNX devices while using Qt Creator, see Connecting QNX devices.

## Third party libraries

Make sure that your system image contains the following additional third-party libraries which are not always included in minimal QNX Neutrino RTOS images:

- `libfontconfig`
- `libfreetype`
- `libiconv`
- `libicui18n`
- `libicudata`
- `libicuuc`
- `libpng16`
- `libxml2`
- `libsqlite3`
- `libssl`
- `libcrypto`
- `libzstd`

Note: This is not a complete list of shared libraries used by Qt on QNX Neutrino OS. Multiple shared libraries are already available in a typical OS image, or included by other parts of the system, for example `Screen`.

See also Qt Configure Options and Configuring Qt.

Qt for QNX Support ◦ Runtime Target Requirements