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  · 

Qt Publish Subscribe Module

The Qt Publish Subscribe module enables applications to read item values, navigate through and subscribe to change notifications.

Overview

The Value Space, inside which all the item values are stored, unifies various sources of hierarchical data into a single consistent model. Conceptually the Value Space is a hierarchical tree of which each node or leaf can optionally contain a QVariant value. A serialized version of a simple example Value Space might look like this:

 /Device/Buttons = 3
 /Device/Buttons/1/Name = Menu
 /Device/Buttons/1/Usable = true
 /Device/Buttons/2/Name = Select
 /Device/Buttons/2/Usable = false
 /Device/Buttons/3/Name = Back
 /Device/Buttons/3/Usable = true

Existing values within the Value Space are accessed through the QValueSpaceSubscriber class. This class provides a means to read values, receive change notifications for a given path and navigate through the Value Space.

New values are added to the Value Space via the QValueSpacePublisher class. This class allows applications to publish values and receive interest notifications when applications connect to a path. Interest notifications can be used to refrain from updating values in the Value Space when there are no interested parties.

Nodes in the Value Space can be thought of as representing schema objects. Obviously this is a conceptual differentiation and not a physical one, as internally the Value Space is treated as one large tree. By applying structured schema to the space "explore-ability" is increased. For example, the /Device/Buttons schema can be defined as containing a value representing the number of mappable buttons on a device, and a sub-item for each adhering to the MappableButton schema. The MappableButton schema itself may be defined as containing two attributes Name and Usable. Change notification is modeled in this fashion also. Were the /Device/Buttons/1/Name item to change, the /Device/Buttons/1 item would also be marked as changed, and so on up the tree. This allows, for example, subscribers to /Device/Buttons to be notified when anything "button" related changes.

Internally, the Value Space consists of an arbitrary number of data source trees, or layers, which are stacked on top of each other to form the final unified view. If two layers contain the same item, e.g. /Device/Buttons, the value in the layer with a higher priority will shadow that with the layer of the lower priority. However, if only the layer with the lower priority contained this item, it would be visible through the QValueSpaceSubscriber class, even if the higher priority layer contained sub-items such as /Device/Buttons/1. That is, layer shadowing occurs by value not by path. Layer priority is fixed and is defined in the layer implementation.

The following Value Space layers are available:

Operating SystemLayerDescription
WindowsNon-volatile Registry LayerThe Non-volatile Registry layer provides a permanent Value Space backing store using keys stored in the Windows' registry.
The Non-volatile Registry layer has a higher priority.
Volatile Registry LayerThe Volatile Registry layer provides a non-permanent Value Space backing store using volatile keys stored in the Windows' registry.
The Volatile Registry layer has a lower priority.
LinuxGConf LayerThe GConf Layer provides a permanent Value Space backing store using GConf. This layer is only available on systems where the GConf is available.
The GConf Layer has a higher priority.
JsonDb LayerThe JsonDb Layer provides a permanent Value Space backing store using QtJsonDb. This layer is only available on systems where the QtJsonDb is available.
The JsonDb Layer has a lower priority.

Detailed Layer Descriptions

GConf Layer

The Qt Publish Subscribe module can be used to access the GConf configuration system.

Limitations of GConf Layer

GConf can natively store only a limited set of QVariant data types. These types are Bool, Int, Double, String, StringList and List. When publishing other data types the values are automatically serialized and stored to GConf as BASE64 encoded strings. When reading these values they are automatically converted back to the original data types. The serialization/deserialization is transparent operation to the API user but may cause interoperatibility issues with native applications that access the same data directly.

Examples

Publish and Subscribe

In the example Publish and Subscribe the Value Space is used as a method of communicating changes in one dialog (the publisher) to another dialog (the subscriber).

Battery Charging - Accessing Publish and Subscribe from QML

In the example Accessing Publish and Subscribe from QML the Publish and Subscribe concept is now extended to make the publisher an input of the level of charge in a battery. A slider on the publisher dialog represents the modifiable level of charge. The Value Space acts as a communications medium between the publisher dialog and the subscriber graphical battery animation. The battery is implemented in QML and C++ with Value Space supplying the charge level for the animation to represent.

Namespaces and Classes

C++ Classes

QValueSpacePublisher

Allows applications to publish values in the Value Space

QValueSpaceSubscriber

Allows applications to read and subscribe to Value Space paths

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.

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