Building Qt 6 requires downloading and installing QNX SDP 7.1 from the QNX website .
注意: A suitable license is required. Contact QNX 了解更多信息。
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
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
,和
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.
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.
To configure and build Qt for QNX, you need the following:
$HOME/qnx.cmake
.
$HOME/qt
.
$HOME/qt-host
.
$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
注意:
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
注意:
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
.
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.
若正使用的 Qt 安装尚未在您的机器中构建,
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 .
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
注意:
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
.
另请参阅 Qt 配置选项 and Configuring Qt .
Qt for QNX Support Qt for QNX Runtime Target Requirements