Qt for OpenHarmony

From Qt Wiki
Revision as of 07:57, 11 September 2024 by Rita Qian (talk | contribs) (change the heading)
Jump to navigation Jump to search

OpenHarmony Introduction

OpenHarmony is an open-source project incubated and operated by the OpenAtom Foundation, with the goal of building a framework and platform for intelligent terminal device operating systems. It aims to cater to the era of full-scenario, full-connectivity, and full-intelligence, and promote the prosperous development of the Internet of Everything industry.

OpenHarmony Open source project

HUAWEI DevEco Studio Installation

If you want to develop Qt for OpenHarmony applications, apart from using Qt Creator, you also need to rely on DevEco Studio.

https://developer.huawei.com/consumer/cn/deveco-studio/

In general, there is no need to configure the sdk version used by DevEco Studio because DevEco Studio comes with one sdk by default.

However, if the included sdk does not meet your needs, you can set the sdk version you want to use by using the following method:

For OpenHarmony 5, you want to install API Version 12 SDK:

DevEco_Studio_Preferences

To avoid any issues caused by the development environment, please first confirm if you can use DevEco Studio to develop Arkts applications.

Gerrit Introduction

The Qt source code is hosted on Gerrit for code review and version control. All needed information about how to work with Gerrit is written on the following pages:

How to get Qt for OpenHarmony source code

  1. Access and login to: https://codereview.qt-project.org.
  2. Click on the "Settings" in the upper right corner to open the settings page.
  3. Click on "Settings" -> "HTTP Credentials" -> "GENERATE NEW PASSWORD" to generate a new password. Save the password for later use with "git clone".
  4. Access https://codereview.qt-project.org/admin/repos/qt/tqtc-qt5, and copy the git repository address.
Codereview-settings.png




GENERATE-NEW-PASSWORD.png








Git-address.png

Building Qt Library for Qt for OpenHarmony in macOS

Prepare for third-party dependencies

Following instruction has been prepared based on macOS Sonoma 14.0. Does not represent a minimum dependency condition.

  • git version 2.39.3
  • python 3.12.0

System environments

Open ~/.zshrc or ~/.bashrc and add the following:

local HARMONY_OS_API_VER=12
local HOME_LIBRARY=${HOME}/Library
export OHOS_SDK_ROOT=${HOME_LIBRARY}/OpenHarmony/Sdk
export HOS_SDK_HOME=${HOME_LIBRARY}/OpenHarmony/Sdk
export OHOS_SDK_12=${HOS_SDK_HOME}/${HARMONY_OS_API_VER}
export NATIVE_OHOS_SDK=${OHOS_SDK_12}/native

Building Qt sources

You can use below script to build Qt for arm64-v8a target.

Please fill-in path to your local source directory.

#!/bin/sh

# Target architecure
ARCH="arm64-v8a"

# Source and build directories
QT5_ROOT_DIR=<ENTER PATH TO YOUR qt/qt5 DIRECORY>
QT5_BUILD_DIR="$QT5_ROOT_DIR/build_${ARCH}"

# Prepare build directory
mkdir "$QT5_BUILD_DIR"
cd "$QT5_BUILD_DIR"

../configure \
    -v \
    -xplatform ohos-clang \
    -prefix ${NATIVE_OHOS_SDK}/opt/Qt/5.12.12/ohos-${ARCH}-clang/ \
    -opensource \
    -confirm-license \
    -release \
    -no-use-gold-linker \
    -no-gcc-sysroot \
    -ohos-arch ${ARCH} \
    -opengles3 \
    -skip qt3d -skip qtactiveqt -skip qtandroidextras -skip qtcanvas3d -skip qtcharts \
    -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtdocgallery -skip qtfeedback \
    -skip qtgamepad -skip qtgraphicaleffects -skip qtlocation -skip qtmacextras -skip qtnetworkauth \
    -skip qtpim -skip qtpurchasing -skip qtqa -skip qtremoteobjects -skip qtrepotools \
    -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport \
    -skip qtspeech -skip qtsystems -skip qttools -skip qttranslations -skip qtvirtualkeyboard \
    -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebglplugin -skip qtwebsockets \
    -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns -skip doc \
    -no-dbus \
    -c++std c++14 \
    -make tests

then,

make -j16
make install

Building Qt Application for OpenHarmony in macOS

Creating development kit for OpenHarmony in Qt Creator

Go to PreferencesKitsQt Versions. Click the button Add….

Macos-qtversion-add.jpg

Configuring Qt Version

Select the qmake file generated by compiling the Qt for OpenHarmony source code:

Macos-oh-qmake.jpg

Configuring Compilers

Go to the Compilers tab. Click on the button Add, then select CustomC.

Oh-compile-c

Set:

Name: OHOS Clang

Compiler path: /path/to/OpenHarmony/Sdk/12/native/llvm/bin/clang

Make Path: /usr/bin/make

ABI: arm - linux - generic - elf - 64bit

Compilers-filled.jpg
Follow the above steps for the C++ compiler. However, this time, make sure to set Name to OHOS Clang++ and in Compiler path select the

clang++ instead.

CppCompilers-filled.jpg

Configuring Kits

Go to Kits tab.

Click the Add button.

Kits.jpg

Setting required environment variables in Qt Creator

Go PreferencesEnvironmentSystem and click the Change… button in Environment section.

Add a new environment variable by adding a line:

NATIVE_OHOS_SDK=/path/to/OpenHarmony/Sdk/12/native

Change-env.jpg

Building Qt Library for OpenHarmony in Windows

Preparing the Build Environment

  • Download MinGW toolchain

For example llvm-mingw-20230919-ucrt-x86_64.zip from Releases · mstorsjo/llvm-mingw Unzip and copy folder for example to d:\

  • Install Perl

Strawberry Perl for Windows

  • Add MinGW and Perl paths to PATH environment variable as shown below:

Add environment variable.png

  • To fix possible opengl errors when running configure run this one off command.

Open command prompt in administrator mode.

Go to your qt5 repo root.

Run hack script(change path to you sysroot location):

python3 hack_the_es2_lack.py D:\oh\DevEcoStudio\sdk\HarmonyOS-NEXT-DB6\openharmony\native\sysroot
  • Open command prompt (cmd.exe was used) and set following environment variables:
REM set NATIVE_OHOS_SDK 
SET NATIVE_OHOS_SDK=D:\oh\DevEcoStudio\sdk\HarmonyOS-NEXT-DB6\openharmony\native

REM set OHOS_SDK_SYSROOT 
SET OHOS_SDK_SYSROOT=%NATIVE_OHOS_SDK%\sysroot

REM set LLVM_INSTALL_DIR 
SET LLVM_INSTALL_DIR=%NATIVE_OHOS_SDK%\llvm

Building

  • With the same command prompt locate to your qt5 repository directory and create build directory parallel to that (Do NOT make the build

directory a subdirectory of the qt5 directory). Then Go to build directory, define a variable with skipped modules and run configure

command:

REM set QT_SKIPS 
SET QT_SKIPS=-skip qt3d -skip qtactiveqt -skip qtandroidextras -skip qtcanvas3d -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtdocgallery -skip qtfeedback -skip qtgamepad -skip qtgraphicaleffects -skip qtlocation -skip qtmacextras -skip qtnetworkauth -skip qtpim -skip qtpurchasing -skip qtqa -skip qtremoteobjects -skip qtrepotools -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qtsystems -skip qttools -skip qttranslations -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebglplugin -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns -no-dbus -skip doc
REM  configure command
call ..\tqtc-qt5\configure.bat -v -xplatform ohos-clang -device-option CROSS_COMPILE=%LLVM_INSTALL_DIR%\bin -prefix c:\Qt\qt-5.12.12-ohos -opensource -confirm-license -debug -no-use-gold-linker %QT_SKIPS% -nomake tests -nomake examples -no-gcc-sysroot -opengles3 -c++std c++14 -ohos-arch arm64-v8a
  • After configure is finished successfully you can start building with mingw32-make:
REM build mingw32-make
mingw32-make -j8
  • After successful build you can start installing with following command:
mingw32-make install

Building Qt Application for OpenHarmony in Windows

TODO

Run the Qt for OpenHamony application to the hardware

TODO