本页内容

HarmonyOS 版 Qt - 从源代码构建

注意: HarmonyOS 版Qt 目前处于技术预览阶段,未来版本中可能会有变动。

本页面介绍了如何配置并从源代码构建HarmonyOS 版 Qt。

先决条件

在继续之前,请确保您已满足《Qt for HarmonyOS 先决条件》中列出的所有要求。

构建 HarmonyOS 版 Qt 属于交叉编译:您需要使用与目标平台对应的宿主平台 Qt 构建中的构建工具,为 HarmonyOS 目标平台构建 Qt 库。因此,您首先需要为宿主平台构建 Qt。有关 Qt 交叉编译的一般背景信息,请参阅《Qt for Device Creation》和《Qt 交叉编译》。

配置与构建

通过将构建指向 OpenHarmony SDK 和主机 Qt 构建来配置 HarmonyOS 版 Qt:

configure -ohos-sdk <SDK_ROOT> -qt-host-path <HOST_QT_PATH> -ohos-arch arm64-v8a
cmake --build .

相关的 configure 选项包括:

  • -ohos-sdk 设置 OpenHarmony SDK 的根路径。若省略,configure 将使用OHOS_SDK_ROOT 环境变量的值。
  • -ohos-arch 设置目标架构。针对物理设备使用arm64-v8a ,针对模拟器使用x86_64 。若省略,configure 将根据 SDK 自动选择架构。
  • -qt-host-path 指定用于交叉编译的 Qt 主机构建路径。

安装

构建完成后,安装 HarmonyOS 版 Qt:

cmake --install .

默认情况下,Qt 安装在/usr/local/Qt-<version> 目录下。若要安装到其他位置,请向configure 传递-prefix 选项。生成的 HarmonyOS 版 Qt 安装包即用于构建和部署应用程序,具体操作请参阅《构建和部署 HarmonyOS 版 Qt 应用程序》。

© 2026 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.