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 to use form of IPC.
The ValueSpacePublisher element allows us to publish key-value pairs of data to a known path. 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 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
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 using the keys 'charge' and 'charging' we will need subscribers for each one
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" } }
The ValueSpacePublisher element represents a path in the value space where keys can be published. |
|
The QValueSpaceSubscriber class allows applications to read and subscribe to Value Space paths. |
© 2008-2011 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners. Privacy Policy
Licensees holding valid Qt Commercial licenses may use this document in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia.
Alternatively, this document may be used under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.