Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

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 QtQuick 2.0
 import Qt.serviceframework 5.0

 // ...
 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 Dialer Example 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 QQmlListProperty 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 Example 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

Service

The Service element holds an instance of a service object.

ServiceList

The ServiceList element holds a list of Service elements.

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web