[经验分享] Qt for OpenHarmony 开发环境搭建笔记 原创

westinyang 显示全部楼层 发表于 2023-11-8 15:16:06

本帖最后由 hyacinth养花人 于 2023-11-20 15:59 编辑

序言

开发环境

  • 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,如下图所示

01.png

则需要在 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 目录下

持续关注

©著作权归作者所有,转载或内容合作请联系作者

您尚未登录,无法参与评论,登录后可以:
参与开源共建问题交流
认同或收藏高质量问答
获取积分成为开源共建先驱

精彩评论1

yiny

沙发 发表于 2024-2-19 23:08:08
什么时候出个编译sdk的教程啊

Copyright   ©2023  OpenHarmony开发者论坛  京ICP备2020036654号-3 |技术支持 Discuz!

返回顶部