Building Qt for QNX

Setting up QNX SDP

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

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

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

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:

However, it is advisable to ensure that you can build Qt for the desktop target on the host as well since the same tools are also needed when compiling for QNX.

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 armv7le)
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.

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, $HOME/qnx.cmake.
  • The Qt source code checked out or installed under $HOME/qt.
  • There is a host build of Qt in $HOME/qt-host.
  • The installation location on the local system is set to $HOME/qnx-install.

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 qnx_install \
-prefix /qt \
-- -DCMAKE_TOOLCHAIN_FILE=$HOME/qnx.cmake  \
$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  \
$HOME/qt

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.

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.

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, 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
  • libpng14
  • libxml2
  • libsqlite3
  • libssl
  • libcrypto

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.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.