Qt for HarmonyOS/qtohosextras doc/Open Link Example
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: