Qt for HarmonyOS/qtohosextras doc/Open Link Example: Difference between revisions
Fix example page conversion (QTFOROH-2307) |
Add code snippets to example pages (QTFOROH-2307) |
||
| Line 8: | Line 8: | ||
The window offers a URL field, an '''App Linking Only''' checkbox and an '''Open App Link''' button. On click the example obtains the default context via QOhosAbilityContext::getDefaultInstance(), creates options with QtOhosExtras::createOpenLinkOptions(), applies QOhosOpenLinkOptions::setAppLinkingOnly() from the checkbox and calls QOhosAbilityContext::tryOpenLink(). A failed call is reported in a warning box. | The window offers a URL field, an '''App Linking Only''' checkbox and an '''Open App Link''' button. On click the example obtains the default context via QOhosAbilityContext::getDefaultInstance(), creates options with QtOhosExtras::createOpenLinkOptions(), applies QOhosOpenLinkOptions::setAppLinkingOnly() from the checkbox and calls QOhosAbilityContext::tryOpenLink(). A failed call is reported in a warning box. | ||
<syntaxhighlight lang="cpp"> | |||
[url, appLinkingOnly]() { | |||
auto abilityContext = QtOhosExtras::QOhosAbilityContext::getDefaultInstance(); | |||
auto openLinkOptions = QtOhosExtras::createOpenLinkOptions(); | |||
openLinkOptions->setAppLinkingOnly(appLinkingOnly->isChecked()); | |||
if (!abilityContext->tryOpenLink(url->text(), *openLinkOptions)) { | |||
QMessageBox::warning(nullptr, "Failed", "Opening the link failed!"); | |||
} | |||
}); | |||
</syntaxhighlight> | |||
* [[Qt_for_HarmonyOS/qtohosextras_doc/Open_Link_Example|abilitycontext/openlink/openlink.pro]] | * [[Qt_for_HarmonyOS/qtohosextras_doc/Open_Link_Example|abilitycontext/openlink/openlink.pro]] | ||
[[Category:Qt for HarmonyOS]] | [[Category:Qt for HarmonyOS]] | ||
Revision as of 10:14, 16 September 2026
< Qt for HarmonyOS / qtohosextras doc
Open Link Example
Demonstrates opening a link with optional App Linking enforcement.
The window offers a URL field, an App Linking Only checkbox and an Open App Link button. On click the example obtains the default context via QOhosAbilityContext::getDefaultInstance(), creates options with QtOhosExtras::createOpenLinkOptions(), applies QOhosOpenLinkOptions::setAppLinkingOnly() from the checkbox and calls QOhosAbilityContext::tryOpenLink(). A failed call is reported in a warning box.
[url, appLinkingOnly]() {
auto abilityContext = QtOhosExtras::QOhosAbilityContext::getDefaultInstance();
auto openLinkOptions = QtOhosExtras::createOpenLinkOptions();
openLinkOptions->setAppLinkingOnly(appLinkingOnly->isChecked());
if (!abilityContext->tryOpenLink(url->text(), *openLinkOptions)) {
QMessageBox::warning(nullptr, "Failed", "Opening the link failed!");
}
});