QtMobility Reference Documentation

Service Framework QML Plugin

Overview

The Service Framework API in the QtMobility Project gives developers a mechanism for discovering and instantiating arbitrary services. The QML Service Framework Plugin enables accessing services in a very easy and simple manner by allowing users to declare a service or find a list of services using QML.

Elements

The service framework QML plugin provides two elements that allow access to registered services via QML script. In general, the QML plugin can only discover and load pre-registered services and does not support any run-time registration or unregistration of services. The servicefw tool can be used to register services to the service framework system prior to running any QML script utilising this plugin. The two available elements are in the subsequent sections.

Service

The Service element provides QML with functionality reflecting the QServiceInterfaceDescriptor class which represents the details of a single service registered on the service framework system. This element also allows the service to be loaded so that it will return a QObject reference of the instantiated service object. If this element is used on its own and not in conjunction to the ServiceList element below, it will represent the default interface at the specified interface name, which is the most convenient use-case of the QML plugin. The code snippet below demonstrates a typical way to load an interface in QML.

 import Qt 4.7
 import QtMobility.serviceframework 1.1
 // ...
 property variant myObject: 0

 Service {
     id: myService
     interfaceName: "com.nokia.qt.examples.ExampleService"

     Component.onCompleted: {
         myObject = myService.serviceObject;
     }
 }

In the above code we use a variant to store the QObject reference provided by the Service::serviceObject. In this case it will be an instance of the default service found at the interface address "com.nokia.qt.examples.ExampleService". The code inside the QML component element is recommended so that the variable myObject holds a valid object instance which can be used throughout the entire QML script.

This element also provides several readable properties about the service interface. A useful one is the Service::valid property which will help debug if the system has found a valid default interface descriptor at the specified interface name. The plugin also allows connecting to signals provided by the service. Here is a typical example of receiving service signals within QML for the above code.

 Connections {
     target: myObject
     ignoreUnknownSignals: true

     onMySignal: {
         // do something
     }
 }

Note the usage of the ignoreUnkownSignals attribute which is useful for ignoring uknown signals, especially in the case where Service::serviceObject has not been called yet or provides an invalid interface.

Once a valid service instance has been obtained its methods and properties can be called and accessed as if it were normal QObject in QML. The service framework example Declarative Notes Manager demonstrates the use of the QML plugin.

ServiceList

The ServiceList element provides QML with functionality reflecting the QServiceFilter class which provides a list of Service elements. A very specific service list element can be defined by using the following code.

 ServiceList {
     id: myServiceList
     serviceName: "MyExampleService"
     interfaceName: "com.nokia.qt.examples.ExampleService"
     versionMatch: ServiceList.Exact
     majorVersion: 1
     minorVersion: 3
 }

If the ServiceList::serviceName is not supplied the filter will search with a default empty string as the service name, meaning all interfaces will be returned regardless of the service name. Similarly if no ServiceList::versionMatch is provided the filter will search with a minimum version match rule.

The actual QDeclarativeListProperty of Service elements can be obtained by reading the ServiceList::services property which searches based on the filter values. This list model can then be used in a list view element.

 ListView {
     id: myListView
     model: myServiceList.services
     delegate: myDelegate
     // ...
 }

The service framework example Declarative Dialer better demonstrates the use of ServiceList coupled with the Service element to search and select a service instance to implement the QML dialer application.

Examples

QML Elements

QML Service Element

The Service element holds an instance of a service object.

QML ServiceList Element

The ServiceList element holds a list of Service elements.

X

Thank you for giving your feedback.

Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.