Qt for OpenHarmony

From Qt Wiki
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/

For OpenHarmony 5, you need to install API Version 12:

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"

# Hack lack of ES2
python3 "$QT5_ROOT_DIR/hack_the_es2_lack.py" ${NATIVE_OHOS_SDK}/sysroot

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

Building Qt Application for OpenHarmony in macOS

Preparing Qt Creator as a Qt IDE

Creating development kit for OpenHarmony in Qt Creator

Go to PreferencesKitsQt Versions.

Click the button Add….

Macos-qtversion-add.jpg






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

Macos-oh-qmake.jpg












TODO