Jump to content

Qt for HarmonyOS/qtohosextras doc/QOhosAppContext Class: Difference between revisions

From Qt Wiki
No edit summary
Drop manual breadcrumb, MediaWiki renders it automatically (QTFOROH-2307)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<!-- Source: qtohosextras-qohosappcontext.html -->
<span id="qohosappcontext-class"></span>
= QOhosAppContext Class =
= QOhosAppContext Class =


<span class="small-subtitle">([[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class|QtOhosExtras::QOhosAppContext]])<br />
class [[Qt_for_HarmonyOS/qtohosextras_doc/Qt_Ohos_Extras_C++_Classes|QtOhosExtras]]::QOhosAppContext
</span>


The [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class|QOhosAppContext]] class contains API to manage native application context. [[#details|More...]]
The QOhosAppContext class contains API to manage native application context. [[#details|More...]]


<div class="table">
{| class="wikitable"
 
{| class="wikitable alignedsummary"
|-
|-
| class="memItemLeft rightAlign topAlign"| Header:
| Header:
| class="memItemRight bottomAlign"| <span class="preprocessor">#include &lt;[[../qtcore/qohosappcontext-sub-qtcore.html|QOhosAppContext]]&gt;</span>
| #include <[https://doc.qt.io/qt-5/qohosappcontext-sub-qtcore.html QOhosAppContext]>
|-
|-
| class="memItemLeft rightAlign topAlign"| qmake:
| qmake:
| class="memItemRight bottomAlign"| QT += ohosextras
| QT += ohosextras
|-
|-
| class="memItemLeft rightAlign topAlign"| Since:
| Since:
| class="memItemRight bottomAlign"| Qt 5.12.12
| Qt 5.12.12
|-
|-
| class="memItemLeft rightAlign topAlign"| Inherits:
| Inherits:
| class="memItemRight bottomAlign"| [[../qtcore/qobject.html|QObject]]
| [https://doc.qt.io/qt-5/qobject.html QObject]
|}
|}


This class was introduced in Qt 5.12.12.


</div>
* [[Qt_for_HarmonyOS/qtohosextras_doc/List_of_All_Members_for_QOhosAppContext|List of all members, including inherited members]]
* [[Qt_for_HarmonyOS/qtohosextras_doc/List_of_All_Members_for_QOhosAppContext|List of all members, including inherited members]]
* [[Qt_for_HarmonyOS/qtohosextras_doc/Obsolete_Members_for_QOhosAppContext|Obsolete members]]


<span id="public-types"></span>
<span id="public-types"></span>
== Public Types ==
== Public Types ==


<div class="table">
{| class="wikitable"
 
{| class="wikitable alignedsummary"
|-
|-
| class="memItemLeft rightAlign topAlign"| enum
| enum class
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#ColorThemeMode-enum|ColorThemeMode]]''' { LightTheme, DarkTheme, FollowSystemSetting }
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#ColorThemeMode-enum|ColorThemeMode]]''' { LightTheme, DarkTheme, FollowSystemSetting }
|}
|}


</div>
<span id="public-functions"></span>
<span id="public-functions"></span>
== Public Functions ==
== Public Functions ==


<div class="table">
{| class="wikitable"
 
|-
{| class="wikitable alignedsummary"
| virtual bool
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActive|darkThemeActive]]'''() const = 0
|-
| virtual void
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#enableContextMenuEventOnLongPress|enableContextMenuEventOnLongPress]]'''() = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual bool
| virtual double
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActive|darkThemeActive]]'''() const = 0
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#fontSizeScale|fontSizeScale]]'''() const = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual void
| virtual QSharedPointer<QOhosBundleInfo>
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#enableContextMenuEventOnLongPress|enableContextMenuEventOnLongPress]]'''() = 0
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getBundleInfo|getBundleInfo]]'''() const = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual double
| virtual bool
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#fontSizeScale|fontSizeScale]]'''() const = 0
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#hasSerialPortAccessRight|hasSerialPortAccessRight]]'''(const QString &''portName'') const = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| int
| virtual bool
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getBundleInfo|getBundleInfo]]'''() const
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#isPermissionGranted|isPermissionGranted]]'''(AppPermissions::Permission ''permission'') const = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual bool
| virtual bool
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#isPermissionGranted|isPermissionGranted]]'''(int ''permission'') const = 0
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#isPermissionGranted-1|isPermissionGranted]]'''(const QString &''permissionName'') const = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual bool
| virtual void
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#isPermissionGranted-1|isPermissionGranted]]'''(const QString &amp;''permissionName'') const = 0
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]'''(AppPermissions::Permission ''permission'') = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual void
| virtual void
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]'''(int ''permission'') = 0
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionOnSettingIfNeeded|requestPermissionOnSettingIfNeeded]]'''(AppPermissions::Permission ''permission'') = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual void
| virtual void
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionOnSettingIfNeeded|requestPermissionOnSettingIfNeeded]]'''(int ''permission'') = 0
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestSerialPortAccessRightIfNeeded|requestSerialPortAccessRightIfNeeded]]'''(const QString &''portName'') = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual void
| virtual void
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#restartApp|restartApp]]'''() = 0
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#restartApp|restartApp]]'''() = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual void
| virtual void
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#restartApp-1|restartApp]]'''(const int &amp;''want'') = 0
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#restartApp-1|restartApp]]'''(const QOhosWant &''requestWant'') = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual void
| virtual void
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#setColorThemeMode|setColorThemeMode]]'''(QtOhosExtras::QOhosAppContext::ColorThemeMode ''mode'') = 0
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#setColorThemeMode|setColorThemeMode]]'''(ColorThemeMode ''mode'') = 0
|}
|}


</div>
* 31 public functions inherited from [[../qtcore/qobject.html#public-functions|QObject]]
<span id="signals"></span>
<span id="signals"></span>
== Signals ==
== Signals ==


<div class="table">
{| class="wikitable"
 
|-
{| class="wikitable alignedsummary"
| void
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActiveChanged|darkThemeActiveChanged]]'''(bool ''darkThemeActive'')
|-
|-
| class="memItemLeft rightAlign topAlign"| void
| void
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActiveChanged|darkThemeActiveChanged]]'''(bool ''darkThemeActive'')
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#fontSizeScaleChanged|fontSizeScaleChanged]]'''(double ''fontSizeScale'')
|-
|-
| class="memItemLeft rightAlign topAlign"| void
| void
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#fontSizeScaleChanged|fontSizeScaleChanged]]'''(double ''fontSizeScale'')
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestOnSettingResponseReceived|permissionRequestOnSettingResponseReceived]]'''(AppPermissions::Permission ''permission'', bool ''permissionGranted'')
|-
|-
| class="memItemLeft rightAlign topAlign"| void
| void
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestOnSettingResponseReceived|permissionRequestOnSettingResponseReceived]]'''(int ''permission'', bool ''permissionGranted'')
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestResponseReceived|permissionRequestResponseReceived]]'''(AppPermissions::Permission ''permission'', bool ''permissionGranted'')
|-
|-
| class="memItemLeft rightAlign topAlign"| void
| void
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestResponseReceived|permissionRequestResponseReceived]]'''(int ''permission'', bool ''permissionGranted'')
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestResponseWithResultReceived|permissionRequestResponseWithResultReceived]]'''(AppPermissions::Permission ''permission'', AppPermissions::PermissionResult ''result'')
|-
|-
| class="memItemLeft rightAlign topAlign"| void
| void
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestResponseWithResultReceived|permissionRequestResponseWithResultReceived]]'''(int ''permission'', int ''result'')
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#serialPortAccessRightResponseReceived|serialPortAccessRightResponseReceived]]'''(const QString &''portName'', QSharedPointer<QObject> ''serialPortAccessRightContext'')
|}
|}


</div>
* 2 signals inherited from [[../qtcore/qobject.html#signals|QObject]]
<span id="static-public-members"></span>
<span id="static-public-members"></span>
== Static Public Members ==
== Static Public Members ==


<div class="table">
{| class="wikitable"
 
{| class="wikitable alignedsummary"
|-
|-
| class="memItemLeft rightAlign topAlign"| int
| QOhosWant
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getAppLaunchWant|getAppLaunchWant]]'''()
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getAppLaunchWant|getAppLaunchWant]]'''()
|-
|-
| class="memItemLeft rightAlign topAlign"| int
| QSharedPointer<QOhosWantInfo>
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getAppLaunchWantInfo|getAppLaunchWantInfo]]'''()
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getAppLaunchWantInfo|getAppLaunchWantInfo]]'''()
|-
|-
| class="memItemLeft rightAlign topAlign"| QtOhosExtras::QOhosAppContext *
| QOhosAppContext *
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#instance|instance]]'''()
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#instance|instance]]'''()
|-
|-
| class="memItemLeft rightAlign topAlign"| bool
| bool
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#isNoUiChildMode|isNoUiChildMode]]'''()
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#isNoUiChildMode|isNoUiChildMode]]'''()
|-
|-
| class="memItemLeft rightAlign topAlign"| void
| void
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#startNoUiChildProcess|startNoUiChildProcess]]'''(QString ''libraryName'', QStringList ''args'')
| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#startNoUiChildProcess|startNoUiChildProcess]]'''(QString ''libraryName'', QStringList ''args'')
|-
| class="memItemLeft rightAlign topAlign"| const QMetaObject
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#staticMetaObject-var|staticMetaObject]]'''
|}
|}


== Detailed Description ==


</div>
== Member Type Documentation ==
* 9 static public members inherited from [[../qtcore/qobject.html#static-public-members|QObject]]


<span id="protected-functions"></span>
=== <span id="ColorThemeMode-enum"></span>enum class QOhosAppContext::ColorThemeMode ===


<span id="protected-functions"></span>
Defines the color theme mode for the application.
== Protected Functions ==
 
<div class="table">


{| class="wikitable alignedsummary"
{| class="wikitable"
|-
|-
| class="memItemLeft rightAlign topAlign"|
! Constant
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#QOhosAppContext|QOhosAppContext]]'''()
! Value
! Description
|-
|-
| class="memItemLeft rightAlign topAlign"|
| <code>QtOhosExtras::QOhosAppContext::ColorThemeMode::LightTheme</code>
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#QOhosAppContext-1|QOhosAppContext]]'''(''const QtOhosExtras::QOhosAppContext &amp;'')
| <code>0</code>
| Uses the light theme colors (default).
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual
| <code>QtOhosExtras::QOhosAppContext::ColorThemeMode::DarkTheme</code>
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#dtor.QOhosAppContext|~QOhosAppContext]]'''() override
| <code>1</code>
| Uses the dark theme colors.
|-
|-
| class="memItemLeft rightAlign topAlign"| QtOhosExtras::QOhosAppContext &amp;
| <code>QtOhosExtras::QOhosAppContext::ColorThemeMode::FollowSystemSetting</code>
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#operator-eq|operator=]]'''(''const QtOhosExtras::QOhosAppContext &amp;'')
| <code>2</code>
| Automatically updates the theme based on the system setting. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-app-ability-environmentcallback-V5#environmentcallbackonconfigurationupdated Configuration Updated].
|}
|}


This enum was introduced or modified in Qt 5.12.12.
== Member Function Documentation ==
=== <span id="darkThemeActiveChanged"></span><code>[signal] </code>void QOhosAppContext::darkThemeActiveChanged(bool ''darkThemeActive'') ===
Signal emitted when the application's color theme changes between dark and light modes. The ''darkThemeActive'' parameter is <code>true</code> when the dark theme became active.
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActive|darkThemeActive]]() and [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#setColorThemeMode|setColorThemeMode]]().
=== <span id="fontSizeScaleChanged"></span><code>[signal] </code>void QOhosAppContext::fontSizeScaleChanged(double ''fontSizeScale'') ===
Signal emitted on system configuration update. ''fontSizeScale'' is the system current font size scale. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-app-ability-environmentcallback-V5#environmentcallbackonconfigurationupdated Configuration Updated].
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#fontSizeScale|fontSizeScale]]().
=== <span id="permissionRequestOnSettingResponseReceived"></span><code>[signal] </code>void QOhosAppContext::permissionRequestOnSettingResponseReceived([[Qt_for_HarmonyOS/qtohosextras_doc/AppPermissions_Namespace#Permission-enum|AppPermissions::Permission]] ''permission'', bool ''permissionGranted'') ===


</div>
Signal emitted on [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionOnSettingIfNeeded|requestPermissionOnSettingIfNeeded]]() request result. Provides ''permissionGranted'' state for a checked ''permission''.
* 9 protected functions inherited from [[../qtcore/qobject.html#protected-functions|QObject]]


<span id="additional-inherited-members"></span>
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionOnSettingIfNeeded|requestPermissionOnSettingIfNeeded]]().
=== Additional Inherited Members ===


* 1 property inherited from [[../qtcore/qobject.html#properties|QObject]]
=== <span id="permissionRequestResponseReceived"></span><code>[signal] </code>void QOhosAppContext::permissionRequestResponseReceived([[Qt_for_HarmonyOS/qtohosextras_doc/AppPermissions_Namespace#Permission-enum|AppPermissions::Permission]] ''permission'', bool ''permissionGranted'') ===
* 1 public slot inherited from [[../qtcore/qobject.html#public-slots|QObject]]


<span id="details"></span>
Signal emitted on [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]() request result. Provides ''permissionGranted'' state for a checked ''permission''.


<div class="descr">
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]().


<span id="details"></span>
=== <span id="permissionRequestResponseWithResultReceived"></span><code>[signal] </code>void QOhosAppContext::permissionRequestResponseWithResultReceived([[Qt_for_HarmonyOS/qtohosextras_doc/AppPermissions_Namespace#Permission-enum|AppPermissions::Permission]] ''permission'', [[Qt_for_HarmonyOS/qtohosextras_doc/PermissionResult_Class|AppPermissions::PermissionResult]] ''result'') ===
== Detailed Description ==
 
Signal emitted on [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]() request result. Provides ''result'' for a checked ''permission''.
 
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]().
 
=== <span id="serialPortAccessRightResponseReceived"></span><code>[signal] </code>void QOhosAppContext::serialPortAccessRightResponseReceived(const [https://doc.qt.io/qt-5/qstring.html QString] &''portName'', [https://doc.qt.io/qt-5/qsharedpointer.html QSharedPointer]<[https://doc.qt.io/qt-5/qobject.html#QObject QObject]> ''serialPortAccessRightContext'') ===


The [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class|QOhosAppContext]] class contains API to manage native application context.
Emitted when the result of [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestSerialPortAccessRightIfNeeded|requestSerialPortAccessRightIfNeeded]](const [https://doc.qt.io/qt-5/qstring.html QString] &portName) becomes available.


The signal provides the ''portName'' corresponding to the response. Additionally, it includes a ''serialPortAccessRightContext'' that defines the access rights granted for the requested serial port. The caller must keep this context alive for as long as access to the serial port is required.


</div>
Destroying or releasing the context automatically cancels the access rights for the associated serial port.
<div class="types">


<span id="member-type-documentation"></span>
If access was not granted, the context will be nullptr.
== Member Type Documentation ==


<span id="ColorThemeMode-enum"></span>
'''Note: '''The lifetime of the access permission is strictly tied to the lifetime of the provided context. Once the last reference to the context is destroyed, the permission request is revoked internally.
=== <span id="ColorThemeMode-enum"></span>enum QOhosAppContext::<span class="name">ColorThemeMode</span> ===


Defines the color theme mode for the application.
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestSerialPortAccessRightIfNeeded|requestSerialPortAccessRightIfNeeded]](const QString &portName).


<div class="table">
=== <span id="darkThemeActive"></span><code>[pure virtual] </code>bool QOhosAppContext::darkThemeActive() const ===


{| class="wikitable valuelist"
Returns whether the dark color theme is active. By default, this function returns `false`, meaning the light theme is used.
|- class="odd" valign="top"
! class="tblConst"| Constant
! class="tblval"| Value
! class="tbldscr"| Description
|-
| class="topAlign"| <code>QtOhosExtras::QOhosAppContext::LightTheme</code>
| class="topAlign tblval"| <code>0</code>
| class="topAlign"| Uses the light theme colors (default).
|-
| class="topAlign"| <code>QtOhosExtras::QOhosAppContext::DarkTheme</code>
| class="topAlign tblval"| <code>1</code>
| class="topAlign"| Uses the dark theme colors.
|-
| class="topAlign"| <code>QtOhosExtras::QOhosAppContext::FollowSystemSetting</code>
| class="topAlign tblval"| <code>2</code>
| class="topAlign"| Automatically updates the theme based on the system setting. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-app-ability-environmentcallback-V5#environmentcallbackonconfigurationupdated Configuration Updated].
|}


'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActiveChanged|darkThemeActiveChanged]]() and [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#setColorThemeMode|setColorThemeMode]]().


</div>
=== <span id="enableContextMenuEventOnLongPress"></span><code>[pure virtual] </code>void QOhosAppContext::enableContextMenuEventOnLongPress() ===
This enum was introduced or modified in Qt 5.12.12.


Enable context menu triggering on long press touch for the entire application lifetime. Mimic Windows long touch behavior by generating a contextMenuEvent with the [https://doc.qt.io/qt-5/qcontextmenuevent.html#Reason-enum QContextMenuEvent::Other] reason.


</div>
The function should be called at the application start, before app.exec();.
<div class="func">


<span id="member-function-documentation"></span>
=== <span id="fontSizeScale"></span><code>[pure virtual] </code>double QOhosAppContext::fontSizeScale() const ===
== Member Function Documentation ==


<code>QOhosAppContext::QOhosAppContext()                              [protected] </code><span id="QOhosAppContext"></span>Default constructs an instance of QOhosAppContext.
Returns font size scale ratio. The value ranges from 0 to 3.2. The default value is 1. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-app-ability-configuration-V5 Font Size Scale].


<code>QOhosAppContext::QOhosAppContext(const QtOhosExtras::QOhosAppContext &)           [protected] </code>Default constructs an instance of QOhosAppContext.
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#fontSizeScaleChanged|fontSizeScaleChanged]](double fontSizeScale).


=== <span id="getAppLaunchWant"></span><code>[static] </code>[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosWant_Class|QOhosWant]] QOhosAppContext::getAppLaunchWant() ===


<code>QOhosAppContext::~QOhosAppContext()                [override virtual protected] </code><span id="dtor.QOhosAppContext"></span>Destroys the instance of QOhosAppContext. The destructor is virtual.
Returns the Want object that was used to launch initial instance of the application's QAbility. It is recommended to use newer [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getAppLaunchWantInfo|getAppLaunchWantInfo]]() method.


<code>bool QOhosAppContext::darkThemeActive() const                  [pure virtual] </code><span id="darkThemeActive"></span>Returns whether the dark color theme is active. By default, this function returns `false`, meaning the light theme is used.
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getAppLaunchWantInfo|getAppLaunchWantInfo]]().


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActiveChanged|darkThemeActiveChanged]]() and [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#setColorThemeMode|setColorThemeMode]]().
=== <span id="getAppLaunchWantInfo"></span><code>[static] </code>[https://doc.qt.io/qt-5/qsharedpointer.html QSharedPointer]<[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosWantInfo_Class|QOhosWantInfo]]> QOhosAppContext::getAppLaunchWantInfo() ===


<code>void QOhosAppContext::darkThemeActiveChanged(bool darkThemeActive)          [signal] </code><span id="darkThemeActiveChanged"></span>Signal emitted when the application's color theme changes between dark and light modes.
Returns the Want object that was used to launch initial instance of the application's QAbility.


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActive|darkThemeActive]]() and [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#setColorThemeMode|setColorThemeMode]]().
=== <span id="getBundleInfo"></span><code>[pure virtual] </code>[https://doc.qt.io/qt-5/qsharedpointer.html QSharedPointer]<[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosBundleInfo_Class|QOhosBundleInfo]]> QOhosAppContext::getBundleInfo() const ===


Returns [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosBundleInfo_Class|QOhosBundleInfo]] object for the current application. The obtained information does not contain information about the signature, HAP module, ability, ExtensionAbility, or permission.


<code>void QOhosAppContext::enableContextMenuEventOnLongPress()      [pure virtual] </code><span id="enableContextMenuEventOnLongPress"></span>Enable context menu triggering on long press touch for the entire application lifetime. Mimic Windows long touch behavior by generating a contextMenuEvent with the [[../qtgui/qcontextmenuevent.html#Reason-enum|QContextMenuEvent::Other]] reason.
=== <span id="hasSerialPortAccessRight"></span><code>[pure virtual] </code>bool QOhosAppContext::hasSerialPortAccessRight(const [https://doc.qt.io/qt-5/qstring.html QString] &''portName'') const ===


The function should be called at the application start, before app.exec();.
Checks whether the application currently has permission to access the serial port identified by ''portName''.


<code>double QOhosAppContext::fontSizeScale() const                  [pure virtual] </code><span id="fontSizeScale"></span>Returns font size scale ratio. The value ranges from 0 to 3.2. The default value is 1. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-app-ability-configuration-V5 Font Size Scale].
Returns <code>true</code> if access rights for the specified serial port are currently granted, otherwise returns <code>false</code>.


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#fontSizeScaleChanged|fontSizeScaleChanged]](double fontSizeScale).
This function performs a synchronous check of the current permission state and does not trigger any permission request. To request access rights when they are not yet granted, use [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestSerialPortAccessRightIfNeeded|requestSerialPortAccessRightIfNeeded]]().


<code>void QOhosAppContext::fontSizeScaleChanged(double fontSizeScale)      [signal] </code><span id="fontSizeScaleChanged"></span>Signal emitted on system configuration update. ''fontSizeScale'' is the system current font size scale. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-app-ability-environmentcallback-V5#environmentcallbackonconfigurationupdated Configuration Updated].
For details about the underlying platform API, see [https://developer.huawei.com/consumer/en/doc/harmonyos-references/js-apis-serialmanager Serial Port Manager].


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#fontSizeScale|fontSizeScale]]().<span id="getAppLaunchWant"></span><code>int QOhosAppContext::getAppLaunchWant()                            [static] </code><span id="getAppLaunchWant"></span>Returns the Want object that was used to launch initial instance of the application's QAbility. It is recommended to use newer [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getAppLaunchWantInfo|getAppLaunchWantInfo]]() method.
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestSerialPortAccessRightIfNeeded|requestSerialPortAccessRightIfNeeded]]().


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getAppLaunchWantInfo|getAppLaunchWantInfo]]().
=== <span id="instance"></span><code>[static] </code>QOhosAppContext *QOhosAppContext::instance() ===


Gets [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class|QOhosAppContext]] global instance.


<code>int QOhosAppContext::getAppLaunchWantInfo()                      [static] </code><span id="getAppLaunchWantInfo"></span>Returns the Want object that was used to launch initial instance of the application's QAbility.
=== <span id="isNoUiChildMode"></span><code>[static] </code>bool QOhosAppContext::isNoUiChildMode() ===


<syntaxhighlight>
Returns true if the current process was started as a "No UI" child.
int QOhosAppContext::getBundleInfo() const
</syntaxhighlight><span id="getBundleInfo"></span>Returns [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosBundleInfo_Class|QOhosBundleInfo]] object for the current application. The obtained information does not contain information about the signature, HAP module, ability, ExtensionAbility, or permission.


<code>QtOhosExtras::QOhosAppContext *QOhosAppContext::instance()            [static] </code><span id="instance"></span>Gets [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class|QOhosAppContext]] global instance.
=== <span id="isPermissionGranted"></span><code>[pure virtual] </code>bool QOhosAppContext::isPermissionGranted([[Qt_for_HarmonyOS/qtohosextras_doc/AppPermissions_Namespace#Permission-enum|AppPermissions::Permission]] ''permission'') const ===


Returns true is a given ''permission'' is granted, false otherwise. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V13/js-apis-abilityaccessctrl-V13#checkaccesstoken9 Check Access Token].


<code>bool QOhosAppContext::isNoUiChildMode()                                [static] </code><span id="isNoUiChildMode"></span>Returns true if the current process was started as a &quot;No UI&quot; child.
=== <span id="isPermissionGranted-1"></span><code>[pure virtual] </code>bool QOhosAppContext::isPermissionGranted(const [https://doc.qt.io/qt-5/qstring.html QString] &''permissionName'') const ===


Returns true if a permission with a given ''permissionName'' is granted, false otherwise. The ''permissionName'' is a full OHOS permission name, for example "ohos.permission.READ_PASTEBOARD". See [https://developer.huawei.com/consumer/en/doc/harmonyos-references/js-apis-abilityaccessctrl#checkaccesstoken9 Check Access Token].


<code>bool QOhosAppContext::isPermissionGranted(int permission) const  [pure virtual] </code><span id="isPermissionGranted"></span>Returns true is a given ''permission'' is granted, false otherwise. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V13/js-apis-abilityaccessctrl-V13#checkaccesstoken9 Check Access Token].
=== <span id="requestPermissionFromUserIfNeeded"></span><code>[pure virtual] </code>void QOhosAppContext::requestPermissionFromUserIfNeeded([[Qt_for_HarmonyOS/qtohosextras_doc/AppPermissions_Namespace#Permission-enum|AppPermissions::Permission]] ''permission'') ===


<code>bool QOhosAppContext::isPermissionGranted(const QString &permissionName) const                                                        [pure virtual] </code><span id="isPermissionGranted-1"></span><code>void QOhosAppContext::permissionRequestOnSettingResponseReceived(int permission, bool permissionGranted)      [signal] </code><span id="permissionRequestOnSettingResponseReceived"></span>Signal emitted on [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionOnSettingIfNeeded|requestPermissionOnSettingIfNeeded]](QtOhosExtras::AppPermissions::Permission permission) request result. Provides ''permissionGranted'' state for a checked ''permission''.
Request a given application ''permission'' from the User. This is asynchronous call which result will be emitted by [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestResponseReceived|permissionRequestResponseReceived]]() signal.


'''See also''' requestPermissionOnSettingIfNeeded(QtOhosExtras::AppPermissions::Permission permission).
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestResponseReceived|permissionRequestResponseReceived]]().


=== <span id="requestPermissionOnSettingIfNeeded"></span><code>[pure virtual] </code>void QOhosAppContext::requestPermissionOnSettingIfNeeded([[Qt_for_HarmonyOS/qtohosextras_doc/AppPermissions_Namespace#Permission-enum|AppPermissions::Permission]] ''permission'') ===


<code>void QOhosAppContext::permissionRequestResponseReceived(int permission, bool permissionGranted)                                  [signal] </code><span id="permissionRequestResponseReceived"></span>Signal emitted on [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]() request result. Provides ''permissionGranted'' state for a checked ''permission''.
Request a given application ''permission'' in a Settings dialog box. This is asynchronous call which result will be emitted by [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestOnSettingResponseReceived|permissionRequestOnSettingResponseReceived]]() signal.


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]().
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestOnSettingResponseReceived|permissionRequestOnSettingResponseReceived]]().


<code>void QOhosAppContext::permissionRequestResponseWithResultReceived(int permission, int result)                                  [signal] </code><span id="permissionRequestResponseWithResultReceived"></span>Signal emitted on [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]() request result. Provides ''result'' for a checked ''permission''.
=== <span id="requestSerialPortAccessRightIfNeeded"></span><code>[pure virtual] </code>void QOhosAppContext::requestSerialPortAccessRightIfNeeded(const [https://doc.qt.io/qt-5/qstring.html QString] &''portName'') ===


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]().
Requests permission for the application to access the serial port identified by ''portName''.


This function performs an asynchronous permission request. The result of the request is delivered via the [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#serialPortAccessRightResponseReceived|serialPortAccessRightResponseReceived]]() signal.


<code>void QOhosAppContext::requestPermissionFromUserIfNeeded(int permission)                                                                                 [pure virtual] </code><span id="requestPermissionFromUserIfNeeded"></span>Request a given application ''permission'' from the User. This is asynchronous call which result will be emitted by [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestResponseReceived|permissionRequestResponseReceived]]() signal.
The outcome of the request (granted or denied) is reported asynchronously through [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#serialPortAccessRightResponseReceived|serialPortAccessRightResponseReceived]](). If access is granted, the signal provides a context object that must be kept alive for as long as the application requires access to the serial port.


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestResponseReceived|permissionRequestResponseReceived]]().
If access is not granted, [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#serialPortAccessRightResponseReceived|serialPortAccessRightResponseReceived]]() signal delivers nullptr. This may happen if:


* a provided ''portName'' cannot be mapped to a valid system serial port,
* an error occurred while requesting the access right,
* user denied the access right.


<code>void QOhosAppContext::requestPermissionOnSettingIfNeeded(int permission)                                            [pure virtual] </code><span id="requestPermissionOnSettingIfNeeded"></span>Request a given application ''permission'' in a Settings dialog box. This is asynchronous call which result will be emitted by [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestOnSettingResponseReceived|permissionRequestOnSettingResponseReceived]]() signal.
For details about the underlying platform API, see [https://developer.huawei.com/consumer/en/doc/harmonyos-references/js-apis-serialmanager Serial Port Manager].


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestOnSettingResponseReceived|permissionRequestOnSettingResponseReceived]]().
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#serialPortAccessRightResponseReceived|serialPortAccessRightResponseReceived]]().


=== <span id="restartApp"></span><code>[pure virtual] </code>void QOhosAppContext::restartApp() ===


<code>void QOhosAppContext::restartApp()                          [pure virtual] </code><span id="restartApp"></span>Restarts the Application using the app launch want.
Restarts the Application using the app launch want.


The current application will be killed using SIGKILL and a new instance of the application will be launched with the application start want.
The current application will be killed using SIGKILL and a new instance of the application will be launched with the application start want.
Line 319: Line 298:
If restartApp is called too frequently, the system call will be throttled to avoid errors.
If restartApp is called too frequently, the system call will be throttled to avoid errors.


Use this function, if you want to restart app with app launch want, instead of calling
Use this function, if you want to restart app with app launch want, instead of calling restartApp(const [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosWant_Class|QOhosWant]] &requestWant) with [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getAppLaunchWant|QOhosAppContext::getAppLaunchWant]]() as a parameter.
 
=== <span id="restartApp-1"></span><code>[pure virtual] </code>void QOhosAppContext::restartApp(const [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosWant_Class|QOhosWant]] &''requestWant'') ===
 
Restarts the Application using the ''requestWant''.
 
The current application will be killed using SIGKILL and a new instance of the application will be launched with the ''requestWant''.
 
All abilities and sub-widnows created within this process will be closed.
 
The application will be killed ungracefully. This function won't return to the caller.
 
The caller must ensure, that the application has system focus when this function is called, otherwise the application will be killed but the new application won't be started. OHOS system treats some system dialogs (for example File Dialog) as separate from the application. If such dialog is open, the application loses the system focus.
 
If restartApp is called too frequently, the system call will be throttled to avoid errors.
 
To call this function with the app launch want (see [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getAppLaunchWant|QOhosAppContext::getAppLaunchWant]]()), use restartApp().
 
<syntaxhighlight lang="cpp">
 
QtOhosExtras::QOhosWant requestWant = QtOhosExtras::QOhosAppContext::getAppLaunchWant();
requestWant.parameters["first_parameter"] = "first_parameter_value";
requestWant.parameters["second_parameter"] = "second_parameter_value";
QtOhosExtras::QOhosAppContext::restartApp(requestWant);
 
</syntaxhighlight>


'''See also''' QtOhosExtras::QOhosAppContext::restartApp(const QtOhosExtras::QOhosWant &amp;requestWant), with, QtOhosExtras::QOhosAppContext::getAppLaunchWant(), as, a, parameter, and ..
=== <span id="setColorThemeMode"></span><code>[pure virtual] </code>void QOhosAppContext::setColorThemeMode([[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#ColorThemeMode-enum|ColorThemeMode]] ''mode'') ===


<code>void QOhosAppContext::restartApp(const int &want)          [pure virtual] </code><span id="restartApp-1"></span><code>void QOhosAppContext::setColorThemeMode(QtOhosExtras::QOhosAppContext::ColorThemeMode mode)                            [pure virtual] </code><span id="setColorThemeMode"></span>Sets the application's color theme to fixed value or enables automatic theme updates.
Sets the application's color theme to fixed value or enables automatic theme updates.


Calling this function with ''mode'' `[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#ColorThemeMode-enum|FollowSystemSetting]]` allows the application to adjust its theme dynamically based on the system's theme configuration. The theme will be updated to match the system theme when `[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#ColorThemeMode-enum|FollowSystemSetting]]` is set. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-app-ability-environmentcallback-V5#environmentcallbackonconfigurationupdated Configuration Updated]. If the color theme actually changes as a result of this call, the [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActiveChanged|darkThemeActiveChanged]]() signal will be emitted.
Calling this function with ''mode'' `[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#ColorThemeMode-enum|FollowSystemSetting]]` allows the application to adjust its theme dynamically based on the system's theme configuration. The theme will be updated to match the system theme when `[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#ColorThemeMode-enum|FollowSystemSetting]]` is set. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-app-ability-environmentcallback-V5#environmentcallbackonconfigurationupdated Configuration Updated]. If the color theme actually changes as a result of this call, the [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActiveChanged|darkThemeActiveChanged]]() signal will be emitted.


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActive|darkThemeActive]]() and [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActiveChanged|darkThemeActiveChanged]]().
'''See also '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActive|darkThemeActive]]() and [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActiveChanged|darkThemeActiveChanged]]().


=== <span id="startNoUiChildProcess"></span><code>[static] </code>void QOhosAppContext::startNoUiChildProcess([https://doc.qt.io/qt-5/qstring.html QString] ''libraryName'', [https://doc.qt.io/qt-5/qstringlist.html QStringList] ''args'') ===


<code>void QOhosAppContext::startNoUiChildProcess(QString libraryName, QStringList args)                                                              [static] </code><span id="startNoUiChildProcess"></span>Starts &quot;No UI&quot; child process for a given ''libraryName'' and ''args''. Arguments passed to the startNoUiChildProcess() function are forwarded to the child's main() function. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-app-ability-childprocessmanager-V5 Child Process Manager].
Starts "No UI" child process for a given ''libraryName'' and ''args''. Arguments passed to the startNoUiChildProcess() function are forwarded to the child's main() function. See [https://developer.huawei.com/consumer/en/doc/harmonyos-references-V5/js-apis-app-ability-childprocessmanager-V5 Child Process Manager].


<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
  QtOhosExtras::QOhosAppContext::startNoUiChildProcess(
  QtOhosExtras::QOhosAppContext::startNoUiChildProcess(
     "libapp.so",
     "libapp.so",
Line 338: Line 344:
         "first arg",
         "first arg",
         "second arg",
         "second arg",
     });</syntaxhighlight>
     });
 
 
<code>QtOhosExtras::QOhosAppContext &QOhosAppContext::operator=(const QtOhosExtras::QOhosAppContext &)                              [protected] </code><span id="operator-eq"></span>Copy-assignment operator.


</syntaxhighlight>


</div>
[[Category:Qt for HarmonyOS]]

Latest revision as of 06:14, 17 September 2026

QOhosAppContext Class

class QtOhosExtras::QOhosAppContext

The QOhosAppContext class contains API to manage native application context. More...

Header: #include <QOhosAppContext>
qmake: QT += ohosextras
Since: Qt 5.12.12
Inherits: QObject

This class was introduced in Qt 5.12.12.

Public Types

enum class ColorThemeMode { LightTheme, DarkTheme, FollowSystemSetting }

Public Functions

virtual bool darkThemeActive() const = 0
virtual void enableContextMenuEventOnLongPress() = 0
virtual double fontSizeScale() const = 0
virtual QSharedPointer<QOhosBundleInfo> getBundleInfo() const = 0
virtual bool hasSerialPortAccessRight(const QString &portName) const = 0
virtual bool isPermissionGranted(AppPermissions::Permission permission) const = 0
virtual bool isPermissionGranted(const QString &permissionName) const = 0
virtual void requestPermissionFromUserIfNeeded(AppPermissions::Permission permission) = 0
virtual void requestPermissionOnSettingIfNeeded(AppPermissions::Permission permission) = 0
virtual void requestSerialPortAccessRightIfNeeded(const QString &portName) = 0
virtual void restartApp() = 0
virtual void restartApp(const QOhosWant &requestWant) = 0
virtual void setColorThemeMode(ColorThemeMode mode) = 0

Signals

void darkThemeActiveChanged(bool darkThemeActive)
void fontSizeScaleChanged(double fontSizeScale)
void permissionRequestOnSettingResponseReceived(AppPermissions::Permission permission, bool permissionGranted)
void permissionRequestResponseReceived(AppPermissions::Permission permission, bool permissionGranted)
void permissionRequestResponseWithResultReceived(AppPermissions::Permission permission, AppPermissions::PermissionResult result)
void serialPortAccessRightResponseReceived(const QString &portName, QSharedPointer<QObject> serialPortAccessRightContext)

Static Public Members

QOhosWant getAppLaunchWant()
QSharedPointer<QOhosWantInfo> getAppLaunchWantInfo()
QOhosAppContext * instance()
bool isNoUiChildMode()
void startNoUiChildProcess(QString libraryName, QStringList args)

Detailed Description

Member Type Documentation

enum class QOhosAppContext::ColorThemeMode

Defines the color theme mode for the application.

Constant Value Description
QtOhosExtras::QOhosAppContext::ColorThemeMode::LightTheme 0 Uses the light theme colors (default).
QtOhosExtras::QOhosAppContext::ColorThemeMode::DarkTheme 1 Uses the dark theme colors.
QtOhosExtras::QOhosAppContext::ColorThemeMode::FollowSystemSetting 2 Automatically updates the theme based on the system setting. See Configuration Updated.

This enum was introduced or modified in Qt 5.12.12.

Member Function Documentation

[signal] void QOhosAppContext::darkThemeActiveChanged(bool darkThemeActive)

Signal emitted when the application's color theme changes between dark and light modes. The darkThemeActive parameter is true when the dark theme became active.

See also darkThemeActive() and setColorThemeMode().

[signal] void QOhosAppContext::fontSizeScaleChanged(double fontSizeScale)

Signal emitted on system configuration update. fontSizeScale is the system current font size scale. See Configuration Updated.

See also fontSizeScale().

[signal] void QOhosAppContext::permissionRequestOnSettingResponseReceived(AppPermissions::Permission permission, bool permissionGranted)

Signal emitted on requestPermissionOnSettingIfNeeded() request result. Provides permissionGranted state for a checked permission.

See also requestPermissionOnSettingIfNeeded().

[signal] void QOhosAppContext::permissionRequestResponseReceived(AppPermissions::Permission permission, bool permissionGranted)

Signal emitted on requestPermissionFromUserIfNeeded() request result. Provides permissionGranted state for a checked permission.

See also requestPermissionFromUserIfNeeded().

[signal] void QOhosAppContext::permissionRequestResponseWithResultReceived(AppPermissions::Permission permission, AppPermissions::PermissionResult result)

Signal emitted on requestPermissionFromUserIfNeeded() request result. Provides result for a checked permission.

See also requestPermissionFromUserIfNeeded().

[signal] void QOhosAppContext::serialPortAccessRightResponseReceived(const QString &portName, QSharedPointer<QObject> serialPortAccessRightContext)

Emitted when the result of requestSerialPortAccessRightIfNeeded(const QString &portName) becomes available.

The signal provides the portName corresponding to the response. Additionally, it includes a serialPortAccessRightContext that defines the access rights granted for the requested serial port. The caller must keep this context alive for as long as access to the serial port is required.

Destroying or releasing the context automatically cancels the access rights for the associated serial port.

If access was not granted, the context will be nullptr.

Note: The lifetime of the access permission is strictly tied to the lifetime of the provided context. Once the last reference to the context is destroyed, the permission request is revoked internally.

See also requestSerialPortAccessRightIfNeeded(const QString &portName).

[pure virtual] bool QOhosAppContext::darkThemeActive() const

Returns whether the dark color theme is active. By default, this function returns `false`, meaning the light theme is used.

See also darkThemeActiveChanged() and setColorThemeMode().

[pure virtual] void QOhosAppContext::enableContextMenuEventOnLongPress()

Enable context menu triggering on long press touch for the entire application lifetime. Mimic Windows long touch behavior by generating a contextMenuEvent with the QContextMenuEvent::Other reason.

The function should be called at the application start, before app.exec();.

[pure virtual] double QOhosAppContext::fontSizeScale() const

Returns font size scale ratio. The value ranges from 0 to 3.2. The default value is 1. See Font Size Scale.

See also fontSizeScaleChanged(double fontSizeScale).

[static] QOhosWant QOhosAppContext::getAppLaunchWant()

Returns the Want object that was used to launch initial instance of the application's QAbility. It is recommended to use newer getAppLaunchWantInfo() method.

See also getAppLaunchWantInfo().

[static] QSharedPointer<QOhosWantInfo> QOhosAppContext::getAppLaunchWantInfo()

Returns the Want object that was used to launch initial instance of the application's QAbility.

[pure virtual] QSharedPointer<QOhosBundleInfo> QOhosAppContext::getBundleInfo() const

Returns QOhosBundleInfo object for the current application. The obtained information does not contain information about the signature, HAP module, ability, ExtensionAbility, or permission.

[pure virtual] bool QOhosAppContext::hasSerialPortAccessRight(const QString &portName) const

Checks whether the application currently has permission to access the serial port identified by portName.

Returns true if access rights for the specified serial port are currently granted, otherwise returns false.

This function performs a synchronous check of the current permission state and does not trigger any permission request. To request access rights when they are not yet granted, use requestSerialPortAccessRightIfNeeded().

For details about the underlying platform API, see Serial Port Manager.

See also requestSerialPortAccessRightIfNeeded().

[static] QOhosAppContext *QOhosAppContext::instance()

Gets QOhosAppContext global instance.

[static] bool QOhosAppContext::isNoUiChildMode()

Returns true if the current process was started as a "No UI" child.

[pure virtual] bool QOhosAppContext::isPermissionGranted(AppPermissions::Permission permission) const

Returns true is a given permission is granted, false otherwise. See Check Access Token.

[pure virtual] bool QOhosAppContext::isPermissionGranted(const QString &permissionName) const

Returns true if a permission with a given permissionName is granted, false otherwise. The permissionName is a full OHOS permission name, for example "ohos.permission.READ_PASTEBOARD". See Check Access Token.

[pure virtual] void QOhosAppContext::requestPermissionFromUserIfNeeded(AppPermissions::Permission permission)

Request a given application permission from the User. This is asynchronous call which result will be emitted by permissionRequestResponseReceived() signal.

See also permissionRequestResponseReceived().

[pure virtual] void QOhosAppContext::requestPermissionOnSettingIfNeeded(AppPermissions::Permission permission)

Request a given application permission in a Settings dialog box. This is asynchronous call which result will be emitted by permissionRequestOnSettingResponseReceived() signal.

See also permissionRequestOnSettingResponseReceived().

[pure virtual] void QOhosAppContext::requestSerialPortAccessRightIfNeeded(const QString &portName)

Requests permission for the application to access the serial port identified by portName.

This function performs an asynchronous permission request. The result of the request is delivered via the serialPortAccessRightResponseReceived() signal.

The outcome of the request (granted or denied) is reported asynchronously through serialPortAccessRightResponseReceived(). If access is granted, the signal provides a context object that must be kept alive for as long as the application requires access to the serial port.

If access is not granted, serialPortAccessRightResponseReceived() signal delivers nullptr. This may happen if:

  • a provided portName cannot be mapped to a valid system serial port,
  • an error occurred while requesting the access right,
  • user denied the access right.

For details about the underlying platform API, see Serial Port Manager.

See also serialPortAccessRightResponseReceived().

[pure virtual] void QOhosAppContext::restartApp()

Restarts the Application using the app launch want.

The current application will be killed using SIGKILL and a new instance of the application will be launched with the application start want.

All abilities and sub-widnows created within this process will be closed.

The application will be killed ungracefully. This function won't return to the caller.

The caller must ensure, that the application has system focus when this function is called, otherwise the application will be killed but the new application won't be started. OHOS system treats some system dialogs (for example File Dialog) as separate from the application. If such dialog is open, the application loses the system focus.

If restartApp is called too frequently, the system call will be throttled to avoid errors.

Use this function, if you want to restart app with app launch want, instead of calling restartApp(const QOhosWant &requestWant) with QOhosAppContext::getAppLaunchWant() as a parameter.

[pure virtual] void QOhosAppContext::restartApp(const QOhosWant &requestWant)

Restarts the Application using the requestWant.

The current application will be killed using SIGKILL and a new instance of the application will be launched with the requestWant.

All abilities and sub-widnows created within this process will be closed.

The application will be killed ungracefully. This function won't return to the caller.

The caller must ensure, that the application has system focus when this function is called, otherwise the application will be killed but the new application won't be started. OHOS system treats some system dialogs (for example File Dialog) as separate from the application. If such dialog is open, the application loses the system focus.

If restartApp is called too frequently, the system call will be throttled to avoid errors.

To call this function with the app launch want (see QOhosAppContext::getAppLaunchWant()), use restartApp().

 QtOhosExtras::QOhosWant requestWant = QtOhosExtras::QOhosAppContext::getAppLaunchWant();
 requestWant.parameters["first_parameter"] = "first_parameter_value";
 requestWant.parameters["second_parameter"] = "second_parameter_value";
 QtOhosExtras::QOhosAppContext::restartApp(requestWant);

[pure virtual] void QOhosAppContext::setColorThemeMode(ColorThemeMode mode)

Sets the application's color theme to fixed value or enables automatic theme updates.

Calling this function with mode `FollowSystemSetting` allows the application to adjust its theme dynamically based on the system's theme configuration. The theme will be updated to match the system theme when `FollowSystemSetting` is set. See Configuration Updated. If the color theme actually changes as a result of this call, the darkThemeActiveChanged() signal will be emitted.

See also darkThemeActive() and darkThemeActiveChanged().

[static] void QOhosAppContext::startNoUiChildProcess(QString libraryName, QStringList args)

Starts "No UI" child process for a given libraryName and args. Arguments passed to the startNoUiChildProcess() function are forwarded to the child's main() function. See Child Process Manager.

 QtOhosExtras::QOhosAppContext::startNoUiChildProcess(
     "libapp.so",
     QStringList{
         "first arg",
         "second arg",
     });