OpenHarmony开发者论坛

标题: Qt for OpenHarmony 开发环境搭建笔记 [打印本页]

作者: westinyang    时间: 2023-11-8 15:16
标题: Qt for OpenHarmony 开发环境搭建笔记
本帖最后由 hyacinth养花人 于 2023-11-20 15:59 编辑

[md]# 序言

- 最终编译的几个Qt示例应用视频演示:
  https://www.bilibili.com/video/BV1NG411Q7QH

# 开发环境

- Windows 11
- DevEco Studio 3.1 Release
- OpenHarmony Full-SDK 3.2.12.5
- Qt For OpenHarmony SDK [Qt5.12.12_alpha_v3](https://gitee.com/openharmony-si ... /Qt5.12.12_alpha_v3)

# 环境搭建

- [OpenHarmony-SIG / qt](https://gitee.com/openharmony-sig/qt)
- [Qt For OpenHarmony SDK使用说明](https://gitee.com/openharmony-si ... 8%E8%AF%B4%E6%98%8E) `先参考仓库文档进行操作`
  - 下载 Qt For OpenHarmony SDK
  - Qt IDE 开发环境配置
  - Qt Widget 示例编译及部署

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

## 环境变量配置问题

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

## 构建套件配置问题

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

![01.png](https://forums-obs.openharmony.c ... 949au998q8uzi8e.png "01.png")

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

```ini
[paths]
Prefix = ..
```

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

## 应用运行闪退问题

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

```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`

```js
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` 目录下

# 持续关注

- OHOS Dev:[https://gitee.com/ohos-dev](https://gitee.com/ohos-dev) `OpenHarmony开源项目组织,为OpenHarmony的未来而创建,Peace & Love`
- BiliBili:[https://space.bilibili.com/74433635](https://space.bilibili.com/74433635) `投稿OpenHarmony探索研究、应用开发和相关技术教程`

[/md]
作者: yiny    时间: 2024-2-19 23:08
什么时候出个编译sdk的教程啊




欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/) Powered by Discuz! X3.5