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" |- |..."
 
No edit summary
Line 238: Line 238:
== Member Function Documentation ==
== Member Function Documentation ==


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


Default constructs an instance of QOhosAppContext.
<code>QOhosAppContext::QOhosAppContext(const QtOhosExtras::QOhosAppContext &)          [protected] </code>Default constructs an instance of QOhosAppContext.


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


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


<span id="dtor.QOhosAppContext"></span>
<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.
=== <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.
 
<span id="darkThemeActive"></span>
=== <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.


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


<span id="darkThemeActiveChanged"></span>
<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.
=== <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.


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#darkThemeActive|darkThemeActive]]() and [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#setColorThemeMode|setColorThemeMode]]().
'''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>
=== <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.
<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.


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>
<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].
=== <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].


'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#fontSizeScaleChanged|fontSizeScaleChanged]](double fontSizeScale).
'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#fontSizeScaleChanged|fontSizeScaleChanged]](double fontSizeScale).


<span id="fontSizeScaleChanged"></span>
<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].
=== <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#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#getAppLaunchWantInfo|getAppLaunchWantInfo]]().
'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#getAppLaunchWantInfo|getAppLaunchWantInfo]]().


<span id="getAppLaunchWantInfo"></span>
=== <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.
<span id="getBundleInfo"></span>
=== <span id="getBundleInfo"></span><span class="type">int</span> QOhosAppContext::<span class="name">getBundleInfo</span>() 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.
<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.
<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>
<syntaxhighlight>
=== <span id="isNoUiChildMode"></span><code>[static] </code><span class="type">bool</span> QOhosAppContext::<span class="name">isNoUiChildMode</span>() ===
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.


Returns true if the current process was started as a &quot;No UI&quot; child.
<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>
=== <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].
<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>
=== <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>
<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="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''.
<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''.


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


<span id="permissionRequestResponseReceived"></span>
=== <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'') ===


Signal emitted on [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]() request result. Provides ''permissionGranted'' state for a checked ''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''.


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


<span id="permissionRequestResponseWithResultReceived"></span>
<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="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 [[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]]().
'''See also''' [[Qt_for_HarmonyOS/qtohosextras_doc/QOhosAppContext_Class#requestPermissionFromUserIfNeeded|requestPermissionFromUserIfNeeded]]().


<span id="requestPermissionFromUserIfNeeded"></span>
=== <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.
<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.


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


<span id="requestPermissionOnSettingIfNeeded"></span>
=== <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'' 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.
<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.


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


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


Restarts the Application using the app launch want.
<code>void QOhosAppContext::restartApp()                          [pure virtual] </code><span id="restartApp"></span>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 377: Line 323:
'''See also''' QtOhosExtras::QOhosAppContext::restartApp(const QtOhosExtras::QOhosWant &amp;requestWant), with, QtOhosExtras::QOhosAppContext::getAppLaunchWant(), as, a, parameter, and ..
'''See also''' QtOhosExtras::QOhosAppContext::restartApp(const QtOhosExtras::QOhosWant &amp;requestWant), with, QtOhosExtras::QOhosAppContext::getAppLaunchWant(), as, a, parameter, and ..


<span id="restartApp-1"></span>
<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.
=== <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>
=== <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'') ===
 
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.
Line 389: Line 329:
'''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>
=== <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].
<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].


<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
Line 401: Line 339:
         "second arg",
         "second arg",
     });</syntaxhighlight>
     });</syntaxhighlight>
<span id="operator-eq"></span>
=== <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;'') ===


Copy-assignment operator.
 
<code>QtOhosExtras::QOhosAppContext &QOhosAppContext::operator=(const QtOhosExtras::QOhosAppContext &)                              [protected] </code><span id="operator-eq"></span>Copy-assignment operator.




</div>
</div>

Revision as of 09:59, 28 January 2026

QOhosAppContext 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


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


  • 31 public functions inherited from QObject

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


  • 9 static public members inherited from QObject

Protected Functions

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


  • 9 protected functions inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject

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. See Configuration Updated.


This enum was introduced or modified in Qt 5.12.12.


Member Function Documentation

QOhosAppContext::QOhosAppContext()                              [protected]
Default constructs an instance of QOhosAppContext.
QOhosAppContext::QOhosAppContext(const QtOhosExtras::QOhosAppContext &)           [protected]
Default constructs an instance of QOhosAppContext.


QOhosAppContext::~QOhosAppContext()                [override virtual protected]
Destroys the instance of QOhosAppContext. The destructor is virtual.
bool QOhosAppContext::darkThemeActive() const                  [pure virtual]
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().

void QOhosAppContext::darkThemeActiveChanged(bool darkThemeActive)           [signal]
Signal emitted when the application's color theme changes between dark and light modes.

See also darkThemeActive() and setColorThemeMode().


void QOhosAppContext::enableContextMenuEventOnLongPress()      [pure virtual]
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();.

double QOhosAppContext::fontSizeScale() const                  [pure virtual]
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).

void QOhosAppContext::fontSizeScaleChanged(double fontSizeScale)       [signal]
Signal emitted on system configuration update. fontSizeScale is the system current font size scale. See Configuration Updated. See also fontSizeScale().
int QOhosAppContext::getAppLaunchWant()                            [static]
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().


int QOhosAppContext::getAppLaunchWantInfo()                      [static]
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.
QtOhosExtras::QOhosAppContext *QOhosAppContext::instance()            [static]
Gets QOhosAppContext global instance.


bool QOhosAppContext::isNoUiChildMode()                                [static]
Returns true if the current process was started as a "No UI" child.


bool QOhosAppContext::isPermissionGranted(int permission) const  [pure virtual]
Returns true is a given permission is granted, false otherwise. See Check Access Token.
bool QOhosAppContext::isPermissionGranted(const QString &permissionName) const                                                        [pure virtual]
void QOhosAppContext::permissionRequestOnSettingResponseReceived(int permission, bool permissionGranted)       [signal]
Signal emitted on requestPermissionOnSettingIfNeeded(QtOhosExtras::AppPermissions::Permission permission) request result. Provides permissionGranted state for a checked permission.

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


void QOhosAppContext::permissionRequestResponseReceived(int permission, bool permissionGranted)                                   [signal]
Signal emitted on requestPermissionFromUserIfNeeded() request result. Provides permissionGranted state for a checked permission.

See also requestPermissionFromUserIfNeeded().

void QOhosAppContext::permissionRequestResponseWithResultReceived(int permission, int result)                                  [signal]
Signal emitted on requestPermissionFromUserIfNeeded() request result. Provides result for a checked permission.

See also requestPermissionFromUserIfNeeded().


void QOhosAppContext::requestPermissionFromUserIfNeeded(int permission)                                                                                 [pure virtual]
Request a given application permission from the User. This is asynchronous call which result will be emitted by permissionRequestResponseReceived() signal.

See also permissionRequestResponseReceived().


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


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

void QOhosAppContext::restartApp(const int &want)           [pure virtual]
void QOhosAppContext::setColorThemeMode(QtOhosExtras::QOhosAppContext::ColorThemeMode mode)                            [pure virtual]
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().


void QOhosAppContext::startNoUiChildProcess(QString libraryName, QStringList args)                                                              [static]
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",
     });


QtOhosExtras::QOhosAppContext &QOhosAppContext::operator=(const QtOhosExtras::QOhosAppContext &)                              [protected]
Copy-assignment operator.