Jump to content

Qt for HarmonyOS development with 6.12.0 Beta2: Difference between revisions

From Qt Wiki
Add Windows section (build & bundling with 6.12.0 Beta2)
Liang Qi (talk | contribs)
 
(One intermediate revision by one other 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 Beta2", including Windows and macOS.
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 Beta2", including macOS and Windows.


== macOS(Apple Silicon) ==
== macOS(Apple Silicon) ==
Line 23: Line 23:
$ mkdir build
$ mkdir build
$ cd build
$ cd build
$ ~/QtSDK/6.12.0/harmonyos_arm64_v8a/bin/qt-cmake -DCMAKE_FIND_ROOT_PATH=~/.local/opt/ohos/additional-packages ..
$ ~/QtSDK/6.12.0/harmonyos_arm64_v8a/bin/qt-cmake -DCMAKE_FIND_ROOT_PATH=/Users/liangqi/.local/opt/ohos/additional-packages ..
$ 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
$ ~/QtSDK/6.12.0/macos/bin/harmonydeployqt --verbose --hvigor /Applications/DevEco-Studio.app/Contents/tools/hvigor/bin/hvigorw --input ./gallery-harmony-deployment-settings.json
Line 29: Line 29:


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 ~/QtSDK/Examples/Qt-6.12.0/widgets/gallery/build/libgallery-harmonyos , sign the package, build it and deploy it to device.


== Windows ==
== Windows ==

Latest revision as of 02:22, 18 July 2026

With Qt Online Installer, you can install binaries for host platforms via "Desktop" item under "Qt 6.12.0 Beta2", including macOS and Windows.

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

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)

$ sudo mkdir -p /opt/harmonyos/command-line-tools/sdk/default/
$ cd /opt/harmonyos/command-line-tools/sdk/default/
$ sudo ln -s /Applications/DevEco-Studio.app/Contents/sdk/default/openharmony ./openharmony

Trying to build an example

$ cd ~/QtSDK/Examples/Qt-6.12.0/widgets/gallery
$ mkdir build
$ cd build
$ ~/QtSDK/6.12.0/harmonyos_arm64_v8a/bin/qt-cmake -DCMAKE_FIND_ROOT_PATH=/Users/liangqi/.local/opt/ohos/additional-packages ..
$ 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

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.

Windows

For examples, you have everything installed at

C:\Qt

. Your host build will be at

C:\Qt\6.12.0\mingw_64

. You can install "HarmonyOS" item under "Qt 6.12.0 Beta2", then you will get it at

C:\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 to

C:\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 at

C:\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\23

and its native toolchain at

%USERPROFILE%\AppData\Local\OpenHarmony\Sdk\23\native

. This guide uses the latter (API 23). Get Additional Packages via https://wiki.qt.io/Building_Qt6_for_HarmonyOS#Additional_Packages , you can put them at

C:\Dev\ohos-additional-packages

.

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, Qt, and additional-packages 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 OHOS_ADDITIONAL_PACKAGES=C:/Dev/ohos-additional-packages
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%" ^
  -DCMAKE_FIND_ROOT_PATH="%OHOS_ADDITIONAL_PACKAGES%"

cmake --build build --parallel

Bundling and deployment

After the build succeeds, run

harmonydeployqt6

to 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\harmonyos_arm64_v8a\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!