Qt for HarmonyOS/qtohosextras doc/Application Continuation Example: Difference between revisions
Add example documentation from qdoc output (QTFOROH-2307) |
Fix example page conversion (QTFOROH-2307) |
||
| Line 15: | Line 15: | ||
'''Note: '''The window is shown before QOhosAbilityContext::getInstanceForMainWindow() is called, so that a valid [https://doc.qt.io/qt-5/qwindow.html QWindow] exists. The restored distributed data object handle is kept alive for as long as the fields should stay in sync, and assets are attached before the object joins a distributed session. | '''Note: '''The window is shown before QOhosAbilityContext::getInstanceForMainWindow() is called, so that a valid [https://doc.qt.io/qt-5/qwindow.html QWindow] exists. The restored distributed data object handle is kept alive for as long as the fields should stay in sync, and assets are attached before the object joins a distributed session. | ||
* [[Qt_for_HarmonyOS/qtohosextras_doc/Application_Continuation_Example|applicationcontinuation/main.cpp]] | * [[Qt_for_HarmonyOS/qtohosextras_doc/Application_Continuation_Example|applicationcontinuation/main.cpp]] | ||
[[Category:Qt for HarmonyOS]] | [[Category:Qt for HarmonyOS]] | ||
Revision as of 09:19, 16 September 2026
< Qt for HarmonyOS / qtohosextras doc
Application Continuation Example
Demonstrates cross-device application continuation with distributed data objects and file assets.
The window shows a set of editable fields, the content of a text file asset, a sync progress label, a checkbox controlling whether the source device exits after migration, and buttons that toggle the continuation state with QOhosAbilityContext::setContinuationActive().
On the source device, the continueRequestReceived() signal delivers a QOhosOnContinueContext. The example builds a QOhosDistributedDataObject from the field values with QOhosDistributedDataObject::create(), attaches the text file with addAssets(), and hands the object over with QOhosOnContinueContext::setResponseOnDistributedDataObjectsSaveResults(). When saving succeeded and QOhosOnContinueContext::sourceApplicationVersionCode() matches the local version code, the request is accepted with setAgreeResponse(); otherwise setMismatchResponse() is called. The checkbox state is applied with setExitAppOnSourceDeviceAfterMigration() before the response is delivered.
On the target device, QtOhosExtras::tryGetOnContinueData() and QtOhosExtras::tryRestoreOnContinueDistributedDataObjects() recover the migrated data. The restored object's dataChanged(), statusChanged() and progressChanged() signals keep the fields, the asset view and the progress label up to date.
Note: The window is shown before QOhosAbilityContext::getInstanceForMainWindow() is called, so that a valid QWindow exists. The restored distributed data object handle is kept alive for as long as the fields should stay in sync, and assets are attached before the object joins a distributed session.