Qt for OpenHarmony 开发环境搭建笔记 原创

westinyang
发布于 2023-11-8 14:24
浏览
2收藏

@toc

关于作者:I’m westinyang

序言

  • 最终编译的几个Qt示例应用视频演示:https://www.bilibili.com/video/BV1NG411Q7QH
  • HarmonyOS 4.0 也是可以运行的,不过要改下runtimeOS配置为HarmonyOS,并签名调试运行到真机上
  • 最终打包的4个Qt示例应用的hap包,见文章末尾附件

开发环境

  • Windows 11
  • DevEco Studio 3.1 Release
  • OpenHarmony Full-SDK 3.2.12.5
  • Qt For OpenHarmony SDK Qt5.12.12_alpha_v3

环境搭建

开源仓库的Wiki中图文并茂,写的比较详细,不过还是有一些遗漏或者有点模糊的地方,下面是我在搭建开发环境是碰到的若干问题,并给出了相应的解决方式

环境变量配置问题

OHOS_SDK_PATH 一定要指向 OpenHarmony SDK 中 native 文件夹的上级目录

构建套件配置问题

如果你碰到提示:Qt没有被正确安装,请运行make install,如下图所示

Qt for OpenHarmony 开发环境搭建笔记-鸿蒙开发者社区

则需要在 qmake.exe 同一文件夹下(qt_oh_sdk_3.2.12.5_bin\Qt5.12.12\aarch64-windows-ohos\bin),创建一个 qt.conf 文件(ANSI格式),内容为:

[paths]
Prefix = ..

然后删除刚才添加的qmake.exe,再重新添加一次即可

应用运行闪退问题

应用运行闪退,查看log定位问题

11-07 18:37:01.188 4663-4663/? W C03f00/ArkCompiler: [default] GetNativeModuleValue:153 GetNativeModuleValue: currentModule /data/storage/el1/bundle/entry/ets/modules.abc, find requireModule @app:com.example.qtdigitalclock/entry/plugins_platforms_qopenharmony failed
11-07 18:37:01.188 4663-4663/? E C03f00/ArkCompiler: [default] Call:1312 occur exception need return
11-07 18:37:01.188 4663-4663/? I C01300/Appkit: [main_thread.cpp(operator():1055)]Js uncaught exception callback come.
11-07 18:37:01.188 4663-4663/? I C01300/Appkit: [main_thread.cpp(operator():1077)]JS Stack:
11-07 18:37:01.188 4663-4663/? I C01300/Appkit:     at anonymous (entry/src/main/ets/native/QtApplication.ts:59:13)
11-07 18:37:01.188 4663-4685/? E C01400/OHOS::ROSEN: print log error in vsprintf_s
11-07 18:37:01.191 4663-4663/? E C01300/Appkit: [main_thread.cpp(operator():1106)]
11-07 18:37:01.191 4663-4663/? E C01300/Appkit: com.example.qtdigitalclock is about to exit due to RuntimeError
11-07 18:37:01.191 4663-4663/? E C01300/Appkit: Error type:TypeError
11-07 18:37:01.191 4663-4663/? E C01300/Appkit: Error message:Cannot read property setDisplayMetrics of undefined
11-07 18:37:01.191 4663-4663/? E C01300/Appkit: SourceCode:
11-07 18:37:01.191 4663-4663/? E C01300/Appkit:             qpa.setDisplayMetrics(d.densityDPI, d.densityPixels, d.scaledDensity, data.width, data.height, data.width, data.height);
11-07 18:37:01.191 4663-4663/? E C01300/Appkit:             ^
11-07 18:37:01.191 4663-4663/? E C01300/Appkit: Stacktrace:
11-07 18:37:01.191 4663-4663/? E C01300/Appkit:     at anonymous (/ets/native/QtApplication.ts:78:7)

找到 src/main/ets/native/QtApplication.ts

import qpa from "libplugins_platforms_qopenharmony.so";

......

this.windowStage.on("windowStageEvent", (state) => {
  qpa.updateApplicationState(state);
  console.log("window stage changed", state);
});

错误原因是找不到 libplugins_platforms_qopenharmony.so

  • 这个so的位置在 qt_oh_sdk_3.2.12.5_bin\Qt5.12.12\aarch64-windows-ohos\plugins\platforms\libplugins_platforms_qopenharmony.so
  • libplugins_platforms_qopenharmony.so 复制到项目的 entry\libs\arm64-v8a 目录下

持续关注

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
QtForOH示例应用安装包4个.zip 35.57M 105次下载
已于2024-1-18 16:52:39修改
4
收藏 2
回复
举报
2条回复
按时间正序
/
按时间倒序
红叶亦知秋
红叶亦知秋

前排学习下

1
回复
2023-11-8 15:44:43
物联风景
物联风景

不错不错,挺好的。

1
回复
2023-11-9 09:11:55
回复
    相关推荐