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. |