Qt for HarmonyOS/qtohosextras doc/Open Link Example: Difference between revisions
Add code snippets to example pages (QTFOROH-2307) |
Drop manual breadcrumb, MediaWiki renders it automatically (QTFOROH-2307) |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
= Open Link Example = | = Open Link Example = | ||
| Line 22: | Line 20: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* [[Qt_for_HarmonyOS/qtohosextras_doc/ | Files: | ||
* [[Qt_for_HarmonyOS/qtohosextras_doc/Open_Link_Example_-_main.cpp|abilitycontext/openlink/main.cpp]] | |||
* [[Qt_for_HarmonyOS/qtohosextras_doc/Open_Link_Example_-_openlink.pro|abilitycontext/openlink/openlink.pro]] | |||
[[Category:Qt for HarmonyOS]] | [[Category:Qt for HarmonyOS]] | ||
Latest revision as of 06:02, 17 September 2026
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!");
}
});
Files: