Jump to content

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

From Qt Wiki
Created page with "<!-- Source: qtohosextras-qohosappcontext.html --> <span id="qohosappcontext-class"></span> = QOhosAppContext Class = <span class="small-subtitle">(QtOhosExtras::QOhosAppContext)<br /> </span> The QOhosAppContext class contains API to manage native application context. More... <div class="table"> {| class="wikitable alignedsummary" |- |..."
 
Add URLs and member functions
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<!-- Source: qtohosextras-qohosappcontext.html -->
< [[Qt_for_HarmonyOS/qtohosextras_doc|Qt for HarmonyOS / qtohosextras doc]]
<span id="qohosappcontext-class"></span>
 
= QOhosAppContext Class =
= QOhosAppContext Class =


<span class="small-subtitle">([[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class|QtOhosExtras::QOhosAppContext]])<br />
The QOhosAppContext class contains API to manage native application context. More...
</span>
 
The [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class|QOhosAppContext]] class contains API to manage native application context. [[#details|More...]]
 
<div class="table">


{| class="wikitable alignedsummary"
{| class="wikitable"
|-
|-
| class="memItemLeft rightAlign topAlign"| Header:
! Header:
| class="memItemRight bottomAlign"| <span class="preprocessor">#include &lt;[[../qtcore/qohosappcontext-sub-qtcore.html|QOhosAppContext]]&gt;</span>
| #include <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]]
| [[QObject_Class|QObject]]
|}
|}


* [[List_of_All_Members_for_QOhosAppContext|List of all members, including inherited members]]
* [[Obsolete_Members_for_QOhosAppContext|Obsolete members]]


</div>
* [[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" style="width:100%"
 
{| class="wikitable alignedsummary"
|-
|-
| class="memItemLeft rightAlign topAlign"| enum
| enum || '''[[#ColorThemeMode-enum|ColorThemeMode]]''' { LightTheme, DarkTheme, FollowSystemSetting }
| class="memItemRight bottomAlign"| '''[[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" style="width:100%"
 
{| class="wikitable alignedsummary"
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual bool
| virtual bool || '''[[#darkThemeActive|darkThemeActive]]'''() const = 0
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActive|darkThemeActive]]'''() const = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual void
| virtual void || '''[[#enableContextMenuEventOnLongPress|enableContextMenuEventOnLongPress]]'''() = 0
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#enableContextMenuEventOnLongPress|enableContextMenuEventOnLongPress]]'''() = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual double
| virtual double || '''[[#fontSizeScale|fontSizeScale]]'''() const = 0
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#fontSizeScale|fontSizeScale]]'''() const = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| int
| int || '''[[#getBundleInfo|getBundleInfo]]'''() const
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getBundleInfo|getBundleInfo]]'''() const
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual bool
| virtual bool || '''[[#isPermissionGranted|isPermissionGranted]]'''(int ''permission'') const = 0
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#isPermissionGranted|isPermissionGranted]]'''(int ''permission'') const = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual bool
| virtual bool || '''[[#isPermissionGranted-1|isPermissionGranted]]'''(const QString &''permissionName'') const = 0
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#isPermissionGranted-1|isPermissionGranted]]'''(const QString &amp;''permissionName'') const = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual void
| virtual void || '''[[#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]'''(int ''permission'') = 0
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]'''(int ''permission'') = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual void
| virtual void || '''[[#requestPermissionOnSettingIfNeeded|requestPermissionOnSettingIfNeeded]]'''(int ''permission'') = 0
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionOnSettingIfNeeded|requestPermissionOnSettingIfNeeded]]'''(int ''permission'') = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual void
| virtual void || '''[[#restartApp|restartApp]]'''() = 0
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#restartApp|restartApp]]'''() = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual void
| virtual void || '''[[#restartApp-1|restartApp]]'''(const int &''want'') = 0
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#restartApp-1|restartApp]]'''(const int &amp;''want'') = 0
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual void
| virtual void || '''[[#setColorThemeMode|setColorThemeMode]]'''(QtOhosExtras::QOhosAppContext::ColorThemeMode ''mode'') = 0
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#setColorThemeMode|setColorThemeMode]]'''(QtOhosExtras::QOhosAppContext::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" style="width:100%"
 
{| class="wikitable alignedsummary"
|-
|-
| class="memItemLeft rightAlign topAlign"| void
| void || '''[[#darkThemeActiveChanged|darkThemeActiveChanged]]'''(bool ''darkThemeActive'')
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActiveChanged|darkThemeActiveChanged]]'''(bool ''darkThemeActive'')
|-
|-
| class="memItemLeft rightAlign topAlign"| void
| void || '''[[#fontSizeScaleChanged|fontSizeScaleChanged]]'''(double ''fontSizeScale'')
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#fontSizeScaleChanged|fontSizeScaleChanged]]'''(double ''fontSizeScale'')
|-
|-
| class="memItemLeft rightAlign topAlign"| void
| void || '''[[#permissionRequestOnSettingResponseReceived|permissionRequestOnSettingResponseReceived]]'''(int ''permission'', bool ''permissionGranted'')
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestOnSettingResponseReceived|permissionRequestOnSettingResponseReceived]]'''(int ''permission'', bool ''permissionGranted'')
|-
|-
| class="memItemLeft rightAlign topAlign"| void
| void || '''[[#permissionRequestResponseReceived|permissionRequestResponseReceived]]'''(int ''permission'', bool ''permissionGranted'')
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestResponseReceived|permissionRequestResponseReceived]]'''(int ''permission'', bool ''permissionGranted'')
|-
|-
| class="memItemLeft rightAlign topAlign"| void
| void || '''[[#permissionRequestResponseWithResultReceived|permissionRequestResponseWithResultReceived]]'''(int ''permission'', int ''result'')
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestResponseWithResultReceived|permissionRequestResponseWithResultReceived]]'''(int ''permission'', int ''result'')
|}
|}


</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" style="width:100%"
 
{| class="wikitable alignedsummary"
|-
|-
| class="memItemLeft rightAlign topAlign"| int
| int || '''[[#getAppLaunchWant|getAppLaunchWant]]'''()
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getAppLaunchWant|getAppLaunchWant]]'''()
|-
|-
| class="memItemLeft rightAlign topAlign"| int
| int || '''[[#getAppLaunchWantInfo|getAppLaunchWantInfo]]'''()
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getAppLaunchWantInfo|getAppLaunchWantInfo]]'''()
|-
|-
| class="memItemLeft rightAlign topAlign"| QtOhosExtras::QOhosAppContext *
| QtOhosExtras::QOhosAppContext * || '''[[#instance|instance]]'''()
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#instance|instance]]'''()
|-
|-
| class="memItemLeft rightAlign topAlign"| bool
| bool || '''[[#isNoUiChildMode|isNoUiChildMode]]'''()
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#isNoUiChildMode|isNoUiChildMode]]'''()
|-
|-
| class="memItemLeft rightAlign topAlign"| void
| void || '''[[#startNoUiChildProcess|startNoUiChildProcess]]'''(QString ''libraryName'', QStringList ''args'')
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#startNoUiChildProcess|startNoUiChildProcess]]'''(QString ''libraryName'', QStringList ''args'')
|-
|-
| class="memItemLeft rightAlign topAlign"| const QMetaObject
| const QMetaObject || '''staticMetaObject'''
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#staticMetaObject-var|staticMetaObject]]'''
|}
|}


</div>
* 9 static public members inherited from [[../qtcore/qobject.html#static-public-members|QObject]]
<span id="protected-functions"></span>
<span id="protected-functions"></span>
== Protected Functions ==
== Protected Functions ==


<div class="table">
{| class="wikitable" style="width:100%"
 
{| class="wikitable alignedsummary"
|-
|-
| class="memItemLeft rightAlign topAlign"|
| || '''[[#QOhosAppContext|QOhosAppContext]]'''()
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#QOhosAppContext|QOhosAppContext]]'''()
|-
|-
| class="memItemLeft rightAlign topAlign"|
| || '''[[#QOhosAppContext-1|QOhosAppContext]]'''(const QtOhosExtras::QOhosAppContext &)
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#QOhosAppContext-1|QOhosAppContext]]'''(''const QtOhosExtras::QOhosAppContext &amp;'')
|-
|-
| class="memItemLeft rightAlign topAlign"| virtual
| virtual || '''[[#dtor.QOhosAppContext|~QOhosAppContext]]'''() override
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#dtor.QOhosAppContext|~QOhosAppContext]]'''() override
|-
|-
| class="memItemLeft rightAlign topAlign"| QtOhosExtras::QOhosAppContext &amp;
| QtOhosExtras::QOhosAppContext & || '''[[#operator-eq|operator=]]'''(const QtOhosExtras::QOhosAppContext &)
| class="memItemRight bottomAlign"| '''[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#operator-eq|operator=]]'''(''const QtOhosExtras::QOhosAppContext &amp;'')
|}
|}


</div>
* 9 protected functions inherited from [[../qtcore/qobject.html#protected-functions|QObject]]
<span id="additional-inherited-members"></span>
=== Additional Inherited Members ===
* 1 property inherited from [[../qtcore/qobject.html#properties|QObject]]
* 1 public slot inherited from [[../qtcore/qobject.html#public-slots|QObject]]
<span id="details"></span>
<div class="descr">
<span id="details"></span>
== Detailed Description ==
== Detailed Description ==


The [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class|QOhosAppContext]] class contains API to manage native application context.
The QOhosAppContext class contains API to manage native application context.
 
 
</div>
<div class="types">


<span id="member-type-documentation"></span>
== Member Type Documentation ==
== Member Type Documentation ==


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


Defines the color theme mode for the application.
Defines the color theme mode for the application.


<div class="table">
{| class="wikitable"
 
! Constant !! Value !! Description
{| class="wikitable valuelist"
|- class="odd" valign="top"
! class="tblConst"| Constant
! class="tblval"| Value
! class="tbldscr"| Description
|-
|-
| class="topAlign"| <code>QtOhosExtras::QOhosAppContext::LightTheme</code>
| QtOhosExtras::QOhosAppContext::LightTheme || 0 || Uses the light theme colors (default).
| class="topAlign tblval"| <code>0</code>
| class="topAlign"| Uses the light theme colors (default).
|-
|-
| class="topAlign"| <code>QtOhosExtras::QOhosAppContext::DarkTheme</code>
| QtOhosExtras::QOhosAppContext::DarkTheme || 1 || Uses the dark theme colors.
| class="topAlign tblval"| <code>1</code>
| class="topAlign"| Uses the dark theme colors.
|-
|-
| class="topAlign"| <code>QtOhosExtras::QOhosAppContext::FollowSystemSetting</code>
| QtOhosExtras::QOhosAppContext::FollowSystemSetting || 2 || Automatically updates the theme based on the system setting.
| 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].
|}
|}


</div>
This enum was introduced or modified in Qt 5.12.12.
</div>
<div class="func">
<span id="member-function-documentation"></span>
== Member Function Documentation ==
== Member Function Documentation ==


<span id="QOhosAppContext"></span>
=== <span id="QOhosAppContext"></span>[protected] QOhosAppContext::QOhosAppContext() ===
=== <span id="QOhosAppContext"></span><code>[protected] </code>QOhosAppContext::<span class="name">QOhosAppContext</span>() ===
 
Default constructs an instance of QOhosAppContext.
Default constructs an instance of QOhosAppContext.


<span id="QOhosAppContext-1"></span>
=== [protected] QOhosAppContext::QOhosAppContext(const QtOhosExtras::QOhosAppContext &) ===
=== <span id="QOhosAppContext-1"></span><code>[protected] </code>QOhosAppContext::<span class="name">QOhosAppContext</span>(''const QtOhosExtras::QOhosAppContext &amp;'') ===
 
Default constructs an instance of QOhosAppContext.
Default constructs an instance of QOhosAppContext.


<span id="dtor.QOhosAppContext"></span>
=== [override virtual protected] QOhosAppContext::~QOhosAppContext() ===
=== <span id="dtor.QOhosAppContext"></span><code>[override virtual protected] </code>QOhosAppContext::<span class="name">~QOhosAppContext</span>() ===
 
Destroys the instance of QOhosAppContext. The destructor is virtual.
Destroys the instance of QOhosAppContext. The destructor is virtual.


<span id="darkThemeActive"></span>
=== <span id="darkThemeActive"></span>[pure virtual] bool QOhosAppContext::darkThemeActive() const ===
=== <span id="darkThemeActive"></span><code>[pure virtual] </code><span class="type">bool</span> QOhosAppContext::<span class="name">darkThemeActive</span>() const ===
 
Returns whether the dark color theme is active. By default, this function returns `false`, meaning the light theme is used.
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#darkThemeActiveChanged|darkThemeActiveChanged]]() and [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#setColorThemeMode|setColorThemeMode]]().
=== [signal] void QOhosAppContext::darkThemeActiveChanged(bool darkThemeActive) ===
 
<span id="darkThemeActiveChanged"></span>
=== <span id="darkThemeActiveChanged"></span><code>[signal] </code><span class="type">void</span> QOhosAppContext::<span class="name">darkThemeActiveChanged</span>(<span class="type">bool</span> ''darkThemeActive'') ===
 
Signal emitted when the application's color theme changes between dark and light modes.
Signal emitted when the application's color theme changes between dark and light modes.


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActive|darkThemeActive]]() and [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#setColorThemeMode|setColorThemeMode]]().
=== <span id="enableContextMenuEventOnLongPress"></span>[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.  
<span id="enableContextMenuEventOnLongPress"></span>
=== <span id="enableContextMenuEventOnLongPress"></span><code>[pure virtual] </code><span class="type">void</span> QOhosAppContext::<span class="name">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.


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


<span id="fontSizeScale"></span>
=== <span id="fontSizeScale"></span>[pure virtual] double QOhosAppContext::fontSizeScale() const ===
=== <span id="fontSizeScale"></span><code>[pure virtual] </code><span class="type">double</span> QOhosAppContext::<span class="name">fontSizeScale</span>() const ===
 
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 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].


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#fontSizeScaleChanged|fontSizeScaleChanged]](double fontSizeScale).
=== [signal] 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].
<span id="fontSizeScaleChanged"></span>
=== <span id="fontSizeScaleChanged"></span><code>[signal] </code><span class="type">void</span> QOhosAppContext::<span class="name">fontSizeScaleChanged</span>(<span class="type">double</span> ''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="getAppLaunchWant"></span>
=== <span id="getAppLaunchWant"></span><code>[static] </code><span class="type">int</span> QOhosAppContext::<span class="name">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#getAppLaunchWantInfo|getAppLaunchWantInfo]]().


<span id="getAppLaunchWantInfo"></span>
=== [static] int QOhosAppContext::getAppLaunchWant() ===
=== <span id="getAppLaunchWantInfo"></span><code>[static] </code><span class="type">int</span> QOhosAppContext::<span class="name">getAppLaunchWantInfo</span>() ===
Returns the Want object that was used to launch initial instance of the application's QAbility. It is recommended to use newer getAppLaunchWantInfo() method.


=== [static] int QOhosAppContext::getAppLaunchWantInfo() ===
Returns the Want object that was used to launch initial instance of the application's QAbility.
Returns the Want object that was used to launch initial instance of the application's QAbility.


<span id="getBundleInfo"></span>
=== <span id="getBundleInfo"></span>int QOhosAppContext::getBundleInfo() const ===
=== <span id="getBundleInfo"></span><span class="type">int</span> QOhosAppContext::<span class="name">getBundleInfo</span>() const ===
Returns [[QOhosBundleInfo_Class|QOhosBundleInfo]] object for the current application. The obtained information does not contain information about the signature, HAP module, ability, ExtensionAbility, or permission.
 
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.
 
<span id="instance"></span>
=== <span id="instance"></span><code>[static] </code><span class="type">[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class|QtOhosExtras::QOhosAppContext]]</span> *QOhosAppContext::<span class="name">instance</span>() ===
 
Gets [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class|QOhosAppContext]] global instance.
 
<span id="isNoUiChildMode"></span>
=== <span id="isNoUiChildMode"></span><code>[static] </code><span class="type">bool</span> QOhosAppContext::<span class="name">isNoUiChildMode</span>() ===
 
Returns true if the current process was started as a &quot;No UI&quot; child.
 
<span id="isPermissionGranted"></span>
=== <span id="isPermissionGranted"></span><code>[pure virtual] </code><span class="type">bool</span> QOhosAppContext::<span class="name">isPermissionGranted</span>(<span class="type">int</span> ''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].
 
<span id="isPermissionGranted-1"></span>
=== <span id="isPermissionGranted-1"></span><code>[pure virtual] </code><span class="type">bool</span> QOhosAppContext::<span class="name">isPermissionGranted</span>(const <span class="type">[[../qtcore/qstring.html|QString]]</span> &amp;''permissionName'') const ===
 
<span id="permissionRequestOnSettingResponseReceived"></span>
=== <span id="permissionRequestOnSettingResponseReceived"></span><code>[signal] </code><span class="type">void</span> QOhosAppContext::<span class="name">permissionRequestOnSettingResponseReceived</span>(<span class="type">int</span> ''permission'', <span class="type">bool</span> ''permissionGranted'') ===
 
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''.


'''See also''' requestPermissionOnSettingIfNeeded(QtOhosExtras::AppPermissions::Permission permission).
=== [static] QtOhosExtras::QOhosAppContext *QOhosAppContext::instance() ===
Gets QOhosAppContext global instance.


<span id="permissionRequestResponseReceived"></span>
=== [static] bool QOhosAppContext::isNoUiChildMode() ===
=== <span id="permissionRequestResponseReceived"></span><code>[signal] </code><span class="type">void</span> QOhosAppContext::<span class="name">permissionRequestResponseReceived</span>(<span class="type">int</span> ''permission'', <span class="type">bool</span> ''permissionGranted'') ===
Returns true if the current process was started as a "No UI" child.


Signal emitted on [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]() request result. Provides ''permissionGranted'' state for a checked ''permission''.
=== <span id="isPermissionGranted"></span>[pure virtual] bool QOhosAppContext::isPermissionGranted(int permission) const ===
Returns true if 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].


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]().
=== [pure virtual] bool QOhosAppContext::isPermissionGranted(const QString &permissionName) const ===


<span id="permissionRequestResponseWithResultReceived"></span>
=== [signal] void QOhosAppContext::permissionRequestOnSettingResponseReceived(int permission, bool permissionGranted) ===
=== <span id="permissionRequestResponseWithResultReceived"></span><code>[signal] </code><span class="type">void</span> QOhosAppContext::<span class="name">permissionRequestResponseWithResultReceived</span>(<span class="type">int</span> ''permission'', <span class="type">int</span> ''result'') ===
Signal emitted on requestPermissionOnSettingIfNeeded(QtOhosExtras::AppPermissions::Permission permission) request result. Provides ''permissionGranted'' state for a checked ''permission''.


Signal emitted on [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]() request result. Provides ''result'' for a checked ''permission''.
See also requestPermissionOnSettingIfNeeded(QtOhosExtras::AppPermissions::Permission permission).


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]().
=== [signal] void QOhosAppContext::permissionRequestResponseReceived(int permission, bool permissionGranted) ===
Signal emitted on requestPermissionFromUserIfNeeded() request result. Provides ''permissionGranted'' state for a checked ''permission''.  


<span id="requestPermissionFromUserIfNeeded"></span>
See also requestPermissionFromUserIfNeeded().
=== <span id="requestPermissionFromUserIfNeeded"></span><code>[pure virtual] </code><span class="type">void</span> QOhosAppContext::<span class="name">requestPermissionFromUserIfNeeded</span>(<span class="type">int</span> ''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.
=== [signal] void QOhosAppContext::permissionRequestResponseWithResultReceived(int permission, int result) ===
Signal emitted on requestPermissionFromUserIfNeeded() request result. Provides ''result'' for a checked ''permission''.  


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


<span id="requestPermissionOnSettingIfNeeded"></span>
=== [pure virtual] void QOhosAppContext::requestPermissionFromUserIfNeeded(int permission) ===
=== <span id="requestPermissionOnSettingIfNeeded"></span><code>[pure virtual] </code><span class="type">void</span> QOhosAppContext::<span class="name">requestPermissionOnSettingIfNeeded</span>(<span class="type">int</span> ''permission'') ===
Request a given application ''permission'' from the User. This is asynchronous call which result will be emitted by permissionRequestResponseReceived() signal.


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 permissionRequestResponseReceived().


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#permissionRequestOnSettingResponseReceived|permissionRequestOnSettingResponseReceived]]().
=== [pure virtual] void QOhosAppContext::requestPermissionOnSettingIfNeeded(int permission) ===
Request a given application ''permission'' in a Settings dialog box. This is asynchronous call which result will be emitted by permissionRequestOnSettingResponseReceived() signal.  


<span id="restartApp"></span>
See also permissionRequestOnSettingResponseReceived().
=== <span id="restartApp"></span><code>[pure virtual] </code><span class="type">void</span> QOhosAppContext::<span class="name">restartApp</span>() ===


=== <span id="restartApp"></span>[pure virtual] void QOhosAppContext::restartApp() ===
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.  
 
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.
All abilities and sub-widnows created within this process will be closed.  


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.
The application will be killed ungracefully. This function won't return to the caller.  


If restartApp is called too frequently, the system call will be throttled to avoid errors.
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.  


Use this function, if you want to restart app with app launch want, instead of calling
If restartApp is called too frequently, the system call will be throttled to avoid errors.


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


<span id="restartApp-1"></span>
See also QtOhosExtras::QOhosAppContext::restartApp(const QtOhosExtras::QOhosWant &requestWant), with, QtOhosExtras::QOhosAppContext::getAppLaunchWant(), as, a, parameter, and ..
=== <span id="restartApp-1"></span><code>[pure virtual] </code><span class="type">void</span> QOhosAppContext::<span class="name">restartApp</span>(const <span class="type">int</span> &amp;''want'') ===


<span id="setColorThemeMode"></span>
=== [pure virtual] void QOhosAppContext::restartApp(const int &want) ===
=== <span id="setColorThemeMode"></span><code>[pure virtual] </code><span class="type">void</span> QOhosAppContext::<span class="name">setColorThemeMode</span>(<span class="type">[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#ColorThemeMode-enum|QtOhosExtras::QOhosAppContext::ColorThemeMode]]</span> ''mode'') ===


=== <span id="setColorThemeMode"></span>[pure virtual] void QOhosAppContext::setColorThemeMode(QtOhosExtras::QOhosAppContext::ColorThemeMode mode) ===
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'' `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 [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 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]]().
 
<span id="startNoUiChildProcess"></span>
=== <span id="startNoUiChildProcess"></span><code>[static] </code><span class="type">void</span> QOhosAppContext::<span class="name">startNoUiChildProcess</span>(<span class="type">[[../qtcore/qstring.html|QString]]</span> ''libraryName'', <span class="type">[[../qtcore/qstringlist.html|QStringList]]</span> ''args'') ===


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].
See also darkThemeActive() and darkThemeActiveChanged().


<syntaxhighlight lang="cpp">
=== <span id="startNoUiChildProcess"></span>[static] void QOhosAppContext::startNoUiChildProcess(QString libraryName, QStringList args) ===
QtOhosExtras::QOhosAppContext::startNoUiChildProcess(
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">
QtOhosExtras::QOhosAppContext::startNoUiChildProcess(
     "libapp.so",
     "libapp.so",
     QStringList{
     QStringList{
         "first arg",
         "first arg",
         "second arg",
         "second arg",
     });</syntaxhighlight>
     });
<span id="operator-eq"></span>
</syntaxhighlight>
=== <span id="operator-eq"></span><code>[protected] </code><span class="type">[[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class|QtOhosExtras::QOhosAppContext]]</span> &amp;QOhosAppContext::<span class="name">operator=</span>(''const QtOhosExtras::QOhosAppContext &amp;'') ===


=== [protected] QtOhosExtras::QOhosAppContext &QOhosAppContext::operator=(const QtOhosExtras::QOhosAppContext &) ===
Copy-assignment operator.
Copy-assignment operator.
 
[[Category:Qt for HarmonyOS]]
 
</div>

Latest revision as of 09:38, 30 January 2026

< Qt for HarmonyOS / qtohosextras doc

QOhosAppContext Class

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

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

Public Types

enum ColorThemeMode { LightTheme, DarkTheme, FollowSystemSetting }

Public Functions

virtual bool darkThemeActive() const = 0
virtual void enableContextMenuEventOnLongPress() = 0
virtual double fontSizeScale() const = 0
int getBundleInfo() const
virtual bool isPermissionGranted(int permission) const = 0
virtual bool isPermissionGranted(const QString &permissionName) const = 0
virtual void requestPermissionFromUserIfNeeded(int permission) = 0
virtual void requestPermissionOnSettingIfNeeded(int permission) = 0
virtual void restartApp() = 0
virtual void restartApp(const int &want) = 0
virtual void setColorThemeMode(QtOhosExtras::QOhosAppContext::ColorThemeMode mode) = 0

Signals

void darkThemeActiveChanged(bool darkThemeActive)
void fontSizeScaleChanged(double fontSizeScale)
void permissionRequestOnSettingResponseReceived(int permission, bool permissionGranted)
void permissionRequestResponseReceived(int permission, bool permissionGranted)
void permissionRequestResponseWithResultReceived(int permission, int result)

Static Public Members

int getAppLaunchWant()
int getAppLaunchWantInfo()
QtOhosExtras::QOhosAppContext * instance()
bool isNoUiChildMode()
void startNoUiChildProcess(QString libraryName, QStringList args)
const QMetaObject staticMetaObject

Protected Functions

QOhosAppContext()
QOhosAppContext(const QtOhosExtras::QOhosAppContext &)
virtual ~QOhosAppContext() override
QtOhosExtras::QOhosAppContext & operator=(const QtOhosExtras::QOhosAppContext &)

Detailed Description

The QOhosAppContext class contains API to manage native application context.

Member Type Documentation

enum QOhosAppContext::ColorThemeMode

Defines the color theme mode for the application.

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

Member Function Documentation

[protected] QOhosAppContext::QOhosAppContext()

Default constructs an instance of QOhosAppContext.

[protected] QOhosAppContext::QOhosAppContext(const QtOhosExtras::QOhosAppContext &)

Default constructs an instance of QOhosAppContext.

[override virtual protected] QOhosAppContext::~QOhosAppContext()

Destroys the instance of QOhosAppContext. The destructor is virtual.

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

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

Signal emitted when the application's color theme changes between dark and light modes.

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

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

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

[static] int 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.

[static] int QOhosAppContext::getAppLaunchWantInfo()

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

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

[static] QtOhosExtras::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(int permission) const

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

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

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

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

See also requestPermissionOnSettingIfNeeded(QtOhosExtras::AppPermissions::Permission permission).

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

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

See also requestPermissionFromUserIfNeeded().

[signal] void QOhosAppContext::permissionRequestResponseWithResultReceived(int permission, int result)

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

See also requestPermissionFromUserIfNeeded().

[pure virtual] void QOhosAppContext::requestPermissionFromUserIfNeeded(int 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(int 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::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.

See also QtOhosExtras::QOhosAppContext::restartApp(const QtOhosExtras::QOhosWant &requestWant), with, QtOhosExtras::QOhosAppContext::getAppLaunchWant(), as, a, parameter, and ..

[pure virtual] void QOhosAppContext::restartApp(const int &want)

[pure virtual] void QOhosAppContext::setColorThemeMode(QtOhosExtras::QOhosAppContext::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",
     });

[protected] QtOhosExtras::QOhosAppContext &QOhosAppContext::operator=(const QtOhosExtras::QOhosAppContext &)

Copy-assignment operator.