在这篇文章中,我们将介绍如何在QML应用中调用Scope,并把搜索的关键词传进去。这对有些QML应用需要用到Scope的情况非常有用。更多关于url-dispatcher的知识,请在文章“使用URL dispatcher的范例”看到。
{ "architecture": "@CLICK_ARCH@", "description": "A simple Unity scope that accesses the network", "framework": "ubuntu-sdk-15.04", "hooks": { "mytestscope": { "apparmor": "mytestscope.apparmor", "scope": "mytestscope" } }, "maintainer": "XiaoGuo, Liu <[email protected]>", "name": "mytestscope.liu-xiao-guo", "title": "mytestscope", "version": "0.1" }
$adb shell
import QtQuick 2.0 import Ubuntu.Components 1.1 /*! \brief MainView with a Label and Button elements. */ MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "launchscopes.liu-xiao-guo" /* This property enables the application to change orientation when the device is rotated. The default is false. */ //automaticOrientation: true // Removes the old toolbar and enables new features of the new header. useDeprecatedToolbar: false width: units.gu(60) height: units.gu(85) Page { title: i18n.tr("launchscopes") Column { anchors.centerIn: parent spacing: units.gu(2) Button { text: "Launch Youtube scope" onClicked: { console.log("it is clicked!"); Qt.openUrlExternally("scope://com.ubuntu.scopes.youtube_youtube"); } } Button { text: "Launch store scope" onClicked: { console.log("it is clicked!"); Qt.openUrlExternally("scope://com.canonical.scopes.clickstore?q=weibo"); } } Button { text: "Launch weibo scope" onClicked: { console.log("it is clicked!"); Qt.openUrlExternally("scope://weibo.ubuntu_weibo"); } } } } }
Qt.openUrlExternally("scope://com.canonical.scopes.clickstore?q=weibo");
scope://com.ubuntu.scopes.youtube_youtube?q=Foo%20Fighters