Jump to content

Qt for HarmonyOS/qtohosextras doc/Restart Application Example: Difference between revisions

From Qt Wiki
Add example documentation from qdoc output (QTFOROH-2307)
 
Drop manual breadcrumb, MediaWiki renders it automatically (QTFOROH-2307)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
< [[Qt_for_HarmonyOS/qtohosextras_doc|Qt for HarmonyOS / qtohosextras doc]]
= Restart Application Example =
= Restart Application Example =


Line 8: Line 6:


The window shows two buttons and a table listing the <code>io.qt</code> launch want parameters read from QOhosAppContext::getAppLaunchWant(). The first button calls QOhosAppContext::restartApp(), which restarts the application with the original launch want and keeps all parameters. The second clears the parameters of the launch want and calls the restartApp(const QOhosWant &) overload, restarting without them.
The window shows two buttons and a table listing the <code>io.qt</code> launch want parameters read from QOhosAppContext::getAppLaunchWant(). The first button calls QOhosAppContext::restartApp(), which restarts the application with the original launch want and keeps all parameters. The second clears the parameters of the launch want and calls the restartApp(const QOhosWant &) overload, restarting without them.
Restarting with the original launch want:
<syntaxhighlight lang="cpp">
            []() {
                QtOhosExtras::QOhosAppContext::instance()->restartApp();
            }));
</syntaxhighlight>
Restarting with a launch want whose parameters have been cleared:
<syntaxhighlight lang="cpp">
            []() {
                auto want = QtOhosExtras::QOhosAppContext::getAppLaunchWant();
                want.parameters = {};
                QtOhosExtras::QOhosAppContext::instance()->restartApp(want);
            }));
</syntaxhighlight>


'''Note: '''restartApp() does not return: the process is terminated and started again. The application must hold system focus when the function is called, and overly frequent restarts are throttled by the system.
'''Note: '''restartApp() does not return: the process is terminated and started again. The application must hold system focus when the function is called, and overly frequent restarts are throttled by the system.
Line 13: Line 33:
Files:
Files:


* [[Qt_for_HarmonyOS/qtohosextras_doc/Restart_Application_Example|restartapp/main.cpp]]
* [[Qt_for_HarmonyOS/qtohosextras_doc/Restart_Application_Example_-_main.cpp|restartapp/main.cpp]]
* [[Qt_for_HarmonyOS/qtohosextras_doc/Restart_Application_Example|restartapp/restartapp.pro]]
* [[Qt_for_HarmonyOS/qtohosextras_doc/Restart_Application_Example_-_restartapp.pro|restartapp/restartapp.pro]]


[[Category:Qt for HarmonyOS]]
[[Category:Qt for HarmonyOS]]

Latest revision as of 06:34, 17 September 2026

Restart Application Example

Demonstrates restarting the application with or without its launch want parameters.


The window shows two buttons and a table listing the io.qt launch want parameters read from QOhosAppContext::getAppLaunchWant(). The first button calls QOhosAppContext::restartApp(), which restarts the application with the original launch want and keeps all parameters. The second clears the parameters of the launch want and calls the restartApp(const QOhosWant &) overload, restarting without them.

Restarting with the original launch want:

             []() {
                 QtOhosExtras::QOhosAppContext::instance()->restartApp();
             }));

Restarting with a launch want whose parameters have been cleared:

             []() {
                 auto want = QtOhosExtras::QOhosAppContext::getAppLaunchWant();
                 want.parameters = {};
                 QtOhosExtras::QOhosAppContext::instance()->restartApp(want);
             }));

Note: restartApp() does not return: the process is terminated and started again. The application must hold system focus when the function is called, and overly frequent restarts are throttled by the system.

Files: