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  · 

Publish and Subscribe QML Plugin

Overview

The Publish and Subscribe QML API enables QML applications to access values stored in the Value Space from QML. The publish/subscribe features therefore allow an easy means of publishing and receiving events and data.

Note: Although the Publish Subscribe plugin simplifies the process of creating and receiving notifications, various platforms may require special actions to be taken before the Publisher and Subscribers are created.

Publisher

The ValueSpacePublisher element allows us to publish key-value pairs of data to a known path. The "known path" is really the "key" of a key/value pair. The path has the form of a directory structure path with the keys acting as files at the end of the path. The process is that the developer declares a ValueSpacePublisher element and then with a given path defines a list of known keys. For example

 ValueSpacePublisher {
     id: battery
     path: "/power/battery"
     keys: ["charge", "charging"]
 }

To publish a value the key need only be set to the value. Here we see that the key is expressed as the last name in the path with dot notation followed by the key name.

     battery.charge = 50
     battery.charging = true

Subscriber

The ValueSpaceSubscriber element also defines the path to the key/value. For each key a different ValueSpaceSubscriber needs to be declared. In the above example where we used the keys 'charge' and 'charging' we will need subscribers for each key

 ValueSpaceSubscriber {
     id: batteryCharge
     path: "/power/battery/charge"
 }
 ValueSpaceSubscriber {
     id: batteryCharging
     path: "/power/battery/charging"
 }

Now the values being published can be read and used

 State {
     name: "low"
     when: batteryCharge.value < 25 && !batteryCharging.value
     PropertyChanges {
         target: visualCharge
         color: "red"
     }
 }

QML Elements

QtPublishSubscribe1::ValueSpacePublisher

The ValueSpacePublisher allows application to publish values to Value Space.

QtPublishSubscribe1::ValueSpaceSubscriber

The QValueSpaceSubscriber class allows applications to read and subscribe to Value Space.

Examples

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