Jump to content

Qt for HarmonyOS development with 6.12.0: Difference between revisions

From Qt Wiki
Add Windows section (build & bundling with 6.12.0 Beta2)
No edit summary
 
(7 intermediate revisions by 2 users 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.
'''Qt 6.12.0 now officially provides prebuilt HarmonyOS packages via the [https://doc-snapshots.qt.io/qt6-6.12/qt-online-installation.html Qt Online Installer]!'''
 
Through the Qt Online Installer, you can check the "HarmonyOS" entry under "Qt 6.12.0" to install the prebuilt Qt libraries for the HarmonyOS target platform.
 
== Installing via Qt Online Installer ==
 
Qt Online Installer download address:
 
https://www.qt.io/development/download-qt-installer-oss
 
Download the version corresponding to your operating system. The following takes installing the Qt 6.12.0 HarmonyOS components as an example.
 
'''1. Launch the installed "Qt Online Installer" and click Next.'''
 
[[File:Qt_harmonyos_installer_01.png|800px|thumb|none|Qt Online Installer welcome screen]]
 
'''2. Enter the login screen, sign in to your Qt account, and click Next.'''
[[File:Qt harmonyos installer 02.png|none|thumb|800x800px|Sign in to Qt account]]
'''3. Check the corresponding terms. Enterprise users must fill in their company name, while individual users should check "I am an individual user", then click Next.'''
[[File:Qt harmonyos installer 03.png|none|thumb|799x799px|Accept terms]]
'''4. If you want to customize the installation directory, click Browse in the upper right corner to select the directory where you want to install Qt. Then check "Custom installation" below and uncheck all other options, and click Next.'''
[[File:Qt harmonyos installer 04.png|none|thumb|800x800px|Select installation directory and custom installation]]
'''5. Sequentially expand "Qt for Development" -> "Qt" -> "Qt 6.12.0", and check "HarmonyOS". Other optional items can be checked as needed, where Sources contains the complete source code of the Qt framework. Once selected, click Next.'''
[[File:Online-installer-6.12-main-page.png|none|thumb|797x797px|Check HarmonyOS component under Qt 6.12.0]]
'''6. Read and accept the license agreement, then click Next.'''
[[File:Qt harmonyos installer 06.png|none|thumb|800x800px|License agreement]]
'''7. You can keep the defaults and click Next.'''
[[File:Qt harmonyos installer 07.png|none|thumb|792x792px|Start menu shortcut settings]]
'''8. Click Install and wait for the installation to complete.'''
[[File:Online-installer-6.12-install-preview.png|left|thumb|791x791px]]
 
[[File:Qt harmonyos installer 09.png|none|thumb|798x798px|Installation in progress]]
 
'''9. Once the installation is complete, click Finish.'''
[[File:Qt harmonyos installer 10.png|none|thumb|800x800px|Installation complete]]
After installation (taking Windows installed to '''C:\Qt''' as an example):
 
* Host (Windows) build is located at: C:\Qt\6.12.0\mingw_64
* HarmonyOS target build is located at: C:\Qt\6.12.0\harmonyos_arm64_v8a


== 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=~/.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 Beta2", 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.


The commands below assume that location. For the SDK, DevEco Studio ships with a bundled one at<code>C:\Huawei\DevEcoStudio\sdk\default\openharmony</code>. If you instead download multiple SDK versions through DevEco Studio's SDK Manager, they land under<code>%USERPROFILE%\AppData\Local\OpenHarmony\Sdk</code>, so API 23 will be at<code>%USERPROFILE%\AppData\Local\OpenHarmony\Sdk\23</code>and its native toolchain at<code>%USERPROFILE%\AppData\Local\OpenHarmony\Sdk\23\native</code>. 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<code>C:\Dev\ohos-additional-packages</code>.
The commands below assume that location. For the SDK, DevEco Studio ships with a bundled one at<code>C:\Huawei\DevEcoStudio\sdk\default\openharmony</code>. If you instead download multiple SDK versions through DevEco Studio's SDK Manager, they land under<code>%USERPROFILE%\AppData\Local\OpenHarmony\Sdk</code>, so API 23 will be at<code>%USERPROFILE%\AppData\Local\OpenHarmony\Sdk\23</code>and its native toolchain at<code>%USERPROFILE%\AppData\Local\OpenHarmony\Sdk\23\native</code>. 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.
'''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 ===
=== 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.<syntaxhighlight lang="bat">
Run the following from a Windows command prompt (cmd). Adjust the paths to match your own SDK and Qt locations.<syntaxhighlight lang="bat">
cd C:\Qt\Examples\Qt-6.12.0\widgets\gallery
cd C:\Qt\Examples\Qt-6.12.0\widgets\gallery


Line 49: Line 85:
SET NATIVE_OHOS_SDK=%OHOS_SDK%/native
SET NATIVE_OHOS_SDK=%OHOS_SDK%/native
SET ARCH="arm64-v8a"
SET ARCH="arm64-v8a"
SET OHOS_ADDITIONAL_PACKAGES=C:/Dev/ohos-additional-packages
SET PATH=%NATIVE_OHOS_SDK%\build-tools\cmake\bin;%PATH%
SET PATH=%NATIVE_OHOS_SDK%\build-tools\cmake\bin;%PATH%


Line 58: Line 93:
   -DOHOS_ARCH=%ARCH% ^
   -DOHOS_ARCH=%ARCH% ^
   -DOHOS_SDK_NATIVE="%NATIVE_OHOS_SDK%" ^
   -DOHOS_SDK_NATIVE="%NATIVE_OHOS_SDK%" ^
  -DCMAKE_FIND_ROOT_PATH="%OHOS_ADDITIONAL_PACKAGES%"


cmake --build build --parallel
cmake --build build --parallel
Line 70: Line 104:
SET PATH=%PATH%;%NODE_HOME%;%JAVA_HOME%
SET PATH=%PATH%;%NODE_HOME%;%JAVA_HOME%


C:\Qt\6.12.0\harmonyos_arm64_v8a\bin\harmonydeployqt6.exe ^
C:\Qt\6.12.0\mingw_64\bin\harmonydeployqt6.exe ^
   --input gallery-harmony-deployment-settings.json ^
   --input gallery-harmony-deployment-settings.json ^
   --output .\tmp ^
   --output .\tmp ^

Latest revision as of 05:11, 19 October 2026

Qt 6.12.0 now officially provides prebuilt HarmonyOS packages via the Qt Online Installer!

Through the Qt Online Installer, you can check the "HarmonyOS" entry under "Qt 6.12.0" to install the prebuilt Qt libraries for the HarmonyOS target platform.

Installing via Qt Online Installer

Qt Online Installer download address:

https://www.qt.io/development/download-qt-installer-oss

Download the version corresponding to your operating system. The following takes installing the Qt 6.12.0 HarmonyOS components as an example.

1. Launch the installed "Qt Online Installer" and click Next.

Qt Online Installer welcome screen

2. Enter the login screen, sign in to your Qt account, and click Next.

Sign in to Qt account

3. Check the corresponding terms. Enterprise users must fill in their company name, while individual users should check "I am an individual user", then click Next.

Accept terms

4. If you want to customize the installation directory, click Browse in the upper right corner to select the directory where you want to install Qt. Then check "Custom installation" below and uncheck all other options, and click Next.

Select installation directory and custom installation

5. Sequentially expand "Qt for Development" -> "Qt" -> "Qt 6.12.0", and check "HarmonyOS". Other optional items can be checked as needed, where Sources contains the complete source code of the Qt framework. Once selected, click Next.

Check HarmonyOS component under Qt 6.12.0

6. Read and accept the license agreement, then click Next.

License agreement

7. You can keep the defaults and click Next.

Start menu shortcut settings

8. Click Install and wait for the installation to complete.

Installation in progress

9. Once the installation is complete, click Finish.

Installation complete

After installation (taking Windows installed to C:\Qt as an example):

  • Host (Windows) build is located at: C:\Qt\6.12.0\mingw_64
  • HarmonyOS target build is located at: C:\Qt\6.12.0\harmonyos_arm64_v8a

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!