Publish and Subscribe QML PluginOverviewThe 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. PublisherThe 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 SubscriberThe 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
Examples |