Jump to content

Qt for HarmonyOS development with 6.12.0: Difference between revisions

From Qt Wiki
changes in Windows: remove the "additional libraries" stuff, modify harmonydeployqt6 path.
Liang Qi (talk | contribs)
upgrade to 6.12.0 final release
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
With [https://doc-snapshots.qt.io/qt6-6.12/qt-online-installation.html Qt Online Installer], you can install binaries for host platforms via "Desktop" item under "Qt 6.12.0 rc", including macOS and Windows. (Note: this works from Qt 6.12.0 rc release.)
With [https://doc-snapshots.qt.io/qt6-6.12/qt-online-installation.html Qt Online Installer], you can install binaries for host platforms via "Desktop" item under "Qt 6.12.0", including macOS and Windows. (Note: this works from Qt 6.12.0 release.)


== macOS(Apple Silicon) ==
== macOS(Apple Silicon) ==


For examples, you have everything installed at ~/QtSDK. Your host build will be at ~/QtSDK/6.12.0/macos . You can install "HarmonyOS" item under "Qt 6.12.0 Beta2", then you will get it at ~/QtSDK/6.12.0/harmonyos_arm64_v8a .
For examples, you have everything installed at ~/Qt. Your host build will be at ~/Qt/6.12.0/macos . You can install "HarmonyOS" item under "Qt 6.12.0", then you will get it at ~/Qt/6.12.0/harmonyos_arm64_v8a .


For DevEco Studio and SDK, you need to install DevEco Studio 6.1.0 Release(DevEco Studio for Mac(ARM) 6.1.0.860(3.4GB)) via https://developer.huawei.com/consumer/cn/deveco-studio/ . Then you will have SDK with API 23 at /Applications/DevEco-Studio.app/Contents/sdk/default/openharmony .
For DevEco Studio and SDK, you need to install DevEco Studio 6.1.0 Release(DevEco Studio for Mac(ARM) 6.1.0.860(3.4GB)) via https://developer.huawei.com/consumer/cn/deveco-studio/ . Then you will have SDK with API 23 at /Applications/DevEco-Studio.app/Contents/sdk/default/openharmony .


===== For Qt 6.12.0 Beta =====
Get Additional Packages via https://wiki.qt.io/Building_Qt6_for_HarmonyOS#Additional_Packages , you can put them at .local/opt/ohos/additional-packages .
Get Additional Packages via https://wiki.qt.io/Building_Qt6_for_HarmonyOS#Additional_Packages , you can put them at .local/opt/ohos/additional-packages .


=== Set SDK path locally(which is from CI setup) ===
(Note: this is not needed from Qt 6.12.0, which starts to use static libs for 3rdparty dependencies, see also https://codereview.qt-project.org/q/topic:%22harmonyos_static_additional_package%22 )


<syntaxhighlight lang="shell">
=== Set OHOS_SDK_ROOT ===
$ sudo mkdir -p /opt/harmonyos/command-line-tools/sdk/default/
 
$ cd /opt/harmonyos/command-line-tools/sdk/default/
<syntaxhighlight lang="shell">$ export OHOS_SDK_ROOT=/Applications/DevEco-Studio.app/Contents/sdk/default/openharmony</syntaxhighlight>
$ sudo ln -s /Applications/DevEco-Studio.app/Contents/sdk/default/openharmony ./openharmony
</syntaxhighlight>


=== Trying to build an example ===
=== Trying to build an example ===


<syntaxhighlight lang="shell">
<syntaxhighlight lang="shell">
$ cd ~/QtSDK/Examples/Qt-6.12.0/widgets/gallery
$ cd ~/Qt/Examples/Qt-6.12.0/widgets/gallery
$ mkdir build
$ mkdir build
$ cd build
$ cd build
$ ~/QtSDK/6.12.0/harmonyos_arm64_v8a/bin/qt-cmake -DCMAKE_FIND_ROOT_PATH=/Users/liangqi/.local/opt/ohos/additional-packages ..
$ ~/Qt/6.12.0/harmonyos_arm64_v8a/bin/qt-cmake ..
$ cmake --build . --parallel
$ cmake --build . --parallel
$ ~/QtSDK/6.12.0/macos/bin/harmonydeployqt --verbose --hvigor /Applications/DevEco-Studio.app/Contents/tools/hvigor/bin/hvigorw --input ./gallery-harmony-deployment-settings.json
$ ~/Qt/6.12.0/macos/bin/harmonydeployqt --verbose --hvigor /Applications/DevEco-Studio.app/Contents/tools/hvigor/bin/hvigorw --input ./gallery-harmony-deployment-settings.json
</syntaxhighlight>
</syntaxhighlight>


Then you can use DevEco Studio to open the project under ~/QtSDK/Examples/Qt-6.12.0/widgets/gallery/build/libgallery-harmonyos , sign the package, build it and deploy it to device.
Then you can use DevEco Studio to open the project under ~/Qt/Examples/Qt-6.12.0/widgets/gallery/build/libgallery-harmonyos , sign the package, build it and deploy it to device.


== Windows ==
== Windows ==
For examples, you have everything installed at<code>C:\Qt</code>. Your host build will be at<code>C:\Qt\6.12.0\mingw_64</code>. You can install "HarmonyOS" item under "Qt 6.12.0 rc", then you will get it at<code>C:\Qt\6.12.0\harmonyos_arm64_v8a</code>. For DevEco Studio and SDK, you need to install DevEco Studio 6.1.0 Release (DevEco Studio for Windows 6.1.0) via https://developer.huawei.com/consumer/cn/deveco-studio/ , and install it to<code>C:\Huawei\DevEcoStudio</code>.
For examples, you have everything installed at<code>C:\Qt</code>. Your host build will be at<code>C:\Qt\6.12.0\mingw_64</code>. You can install "HarmonyOS" item under "Qt 6.12.0", then you will get it at<code>C:\Qt\6.12.0\harmonyos_arm64_v8a</code>. For DevEco Studio and SDK, you need to install DevEco Studio 6.1.0 Release (DevEco Studio for Windows 6.1.0) via https://developer.huawei.com/consumer/cn/deveco-studio/ , and install it to<code>C:\Huawei\DevEcoStudio</code>.


'''Note on the DevEco Studio path:''' DevEco Studio installs by default under C:\Program Files\Huawei\DevEco Studio. Spaces in that path can cause failures during the cross-compile build/bundling steps, which is why installing it to a space-free path such as C:\Huawei\DevEcoStudio is recommended.
'''Note on the DevEco Studio path:''' DevEco Studio installs by default under C:\Program Files\Huawei\DevEco Studio. Spaces in that path can cause failures during the cross-compile build/bundling steps, which is why installing it to a space-free path such as C:\Huawei\DevEcoStudio is recommended.

Latest revision as of 03:39, 1 October 2026

With Qt Online Installer, you can install binaries for host platforms via "Desktop" item under "Qt 6.12.0", including macOS and Windows. (Note: this works from Qt 6.12.0 release.)

macOS(Apple Silicon)

For examples, you have everything installed at ~/Qt. Your host build will be at ~/Qt/6.12.0/macos . You can install "HarmonyOS" item under "Qt 6.12.0", then you will get it at ~/Qt/6.12.0/harmonyos_arm64_v8a .

For DevEco Studio and SDK, you need to install DevEco Studio 6.1.0 Release(DevEco Studio for Mac(ARM) 6.1.0.860(3.4GB)) via https://developer.huawei.com/consumer/cn/deveco-studio/ . Then you will have SDK with API 23 at /Applications/DevEco-Studio.app/Contents/sdk/default/openharmony .

For Qt 6.12.0 Beta

Get Additional Packages via https://wiki.qt.io/Building_Qt6_for_HarmonyOS#Additional_Packages , you can put them at .local/opt/ohos/additional-packages .

(Note: this is not needed from Qt 6.12.0, which starts to use static libs for 3rdparty dependencies, see also https://codereview.qt-project.org/q/topic:%22harmonyos_static_additional_package%22 )

Set OHOS_SDK_ROOT

$ export OHOS_SDK_ROOT=/Applications/DevEco-Studio.app/Contents/sdk/default/openharmony

Trying to build an example

$ cd ~/Qt/Examples/Qt-6.12.0/widgets/gallery
$ mkdir build
$ cd build
$ ~/Qt/6.12.0/harmonyos_arm64_v8a/bin/qt-cmake ..
$ cmake --build . --parallel
$ ~/Qt/6.12.0/macos/bin/harmonydeployqt --verbose --hvigor /Applications/DevEco-Studio.app/Contents/tools/hvigor/bin/hvigorw --input ./gallery-harmony-deployment-settings.json

Then you can use DevEco Studio to open the project under ~/Qt/Examples/Qt-6.12.0/widgets/gallery/build/libgallery-harmonyos , sign the package, build it and deploy it to device.

Windows

For examples, you have everything installed atC:\Qt. Your host build will be atC:\Qt\6.12.0\mingw_64. You can install "HarmonyOS" item under "Qt 6.12.0", then you will get it atC:\Qt\6.12.0\harmonyos_arm64_v8a. For DevEco Studio and SDK, you need to install DevEco Studio 6.1.0 Release (DevEco Studio for Windows 6.1.0) via https://developer.huawei.com/consumer/cn/deveco-studio/ , and install it toC:\Huawei\DevEcoStudio.

Note on the DevEco Studio path: DevEco Studio installs by default under C:\Program Files\Huawei\DevEco Studio. Spaces in that path can cause failures during the cross-compile build/bundling steps, which is why installing it to a space-free path such as C:\Huawei\DevEcoStudio is recommended.

The commands below assume that location. For the SDK, DevEco Studio ships with a bundled one atC:\Huawei\DevEcoStudio\sdk\default\openharmony. If you instead download multiple SDK versions through DevEco Studio's SDK Manager, they land under%USERPROFILE%\AppData\Local\OpenHarmony\Sdk, so API 23 will be at%USERPROFILE%\AppData\Local\OpenHarmony\Sdk\23and its native toolchain at%USERPROFILE%\AppData\Local\OpenHarmony\Sdk\23\native. This guide uses the latter (API 23).

Note on install locations: the paths above are what this guide assumes; they will differ per machine, so adjust them to match your own setup.

Trying to build an example

Run the following from a Windows command prompt (cmd). Adjust the paths to match your own SDK and Qt locations.

cd C:\Qt\Examples\Qt-6.12.0\widgets\gallery

SET HARMONY_OS_API_VER=23
SET OHOS_SDK_ROOT=%USERPROFILE%/AppData/Local/OpenHarmony/Sdk
SET OHOS_SDK=%OHOS_SDK_ROOT%/%HARMONY_OS_API_VER%
SET NATIVE_OHOS_SDK=%OHOS_SDK%/native
SET ARCH="arm64-v8a"
SET PATH=%NATIVE_OHOS_SDK%\build-tools\cmake\bin;%PATH%

C:\Qt\6.12.0\harmonyos_arm64_v8a\bin\qt-cmake.bat -B build -S . -G Ninja ^
  -DCMAKE_TOOLCHAIN_FILE="C:/Qt/6.12.0/harmonyos_arm64_v8a/lib/cmake/Qt6/qt.toolchain.cmake" ^
  -DQT_HOST_PATH="C:/Qt/6.12.0/mingw_64" ^
  -DQT_CHAINLOAD_TOOLCHAIN_FILE="%NATIVE_OHOS_SDK%/build/cmake/ohos.toolchain.cmake" ^
  -DOHOS_ARCH=%ARCH% ^
  -DOHOS_SDK_NATIVE="%NATIVE_OHOS_SDK%" ^

cmake --build build --parallel

Bundling and deployment

After the build succeeds, runharmonydeployqt6to generate the DevEco Studio project. Set the environment variables so the bundling step finds Node.js, the JDK, and the DevEco SDK. Node.js and the JDK (jbr) are bundled with DevEco Studio.

SET NODE_HOME=C:/Huawei/DevEcoStudio/tools/node
SET JAVA_HOME=C:/Huawei/DevEcoStudio/jbr/bin
SET DEVECO_SDK_HOME=C:/Huawei/DevEcoStudio
SET PATH=%PATH%;%NODE_HOME%;%JAVA_HOME%

C:\Qt\6.12.0\mingw_64\bin\harmonydeployqt6.exe ^
  --input gallery-harmony-deployment-settings.json ^
  --output .\tmp ^
  --verbose ^
  --hvigor C:\Huawei\DevEcoStudio\tools\hvigor\bin\hvigorw.bat

Then you can use DevEco Studio to open the generated project under the output directory.\tmp, then sign the package, build it and deploy it to device.

Reference

Happy Hacking!