为 HarmonyOS 构建和部署 Qt 应用程序
注意: HarmonyOS 版Qt 目前处于技术预览阶段,未来版本可能会有变动。
本页面介绍了如何为 HarmonyOS 构建和打包 Qt 应用程序,以及如何在设备或模拟器上运行该应用程序。
打包为 HAP
注意:您可以 使用 CMake 或 qmake 构建 HarmonyOS 版的 Qt 应用程序,但将应用程序打包为 HAP 并进行部署仅支持使用 CMake。
HarmonyOS 应用程序以 HarmonyOS 能力包(HAP)的形式发布。当您在针对 HarmonyOS 开发时使用qt_add_executable()创建 Qt 应用程序可执行文件时,Qt 会自动生成一个名为 `<target>_make_hap ` 的构建目标。构建该目标将生成您应用程序的 HAP:
cmake --build . --target <target>_make_hap部署原理
<target>_make_hap 目标会运行 HarmonyOS 部署工具harmonydeployqt。 其工作原理与androiddeployqt 相同:它会收集应用程序的共享库、HarmonyOS 平台插件(libqohos.so )、所需的 Qt 模块,以及针对Qt Quick 应用程序的 QML 模块,并将它们放入 HarmonyOS 应用程序模板中。随后,它会调用 OpenHarmonyhvigor 构建工具来组装最终的 HAP。
要配置写入 HarmonyOS 清单文件(app.json5 和module.json5 )中的元数据以及声明权限,请使用《Qt for HarmonyOS CMake API》中描述的命令。
运行应用程序
在已连接的 HarmonyOS 设备或模拟器上安装并运行生成的 HAP。部署和调试的最便捷方式是在DevEco Studio中打开生成的项目,并使用其运行和调试工具。
© 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.