Debian Codegraph @

doc/src/publishsubscribe/plugins/qml-publishsubscribe.qdoc

raw
1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:FDL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Free Documentation License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Free
19 ** Documentation License version 1.3 as published by the Free Software
20 ** Foundation and appearing in the file included in the packaging of
21 ** this file. Please review the following information to ensure
22 ** the GNU Free Documentation License version 1.3 requirements
23 ** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
24 ** $QT_END_LICENSE$
25 **
26 ****************************************************************************/
27
28 /*!
29 \group qml-publishsubscribe
30 \title QML Publish and Subscribe API Plugin
31 QML Support for the Qt Publish and Subscribe API.
32 */
33
34 /*!
35 \page qml-publishsubscribe.html
36 \title Publish and Subscribe QML Plugin
37 \brief A QML plugin for the Qt Publish and Subscribe API.
38
39 \section1 Overview
40
41 The Publish and Subscribe QML API enables QML applications to access
42 values stored in the Value Space from QML. The publish/subscribe features
43 therefore allow an easy means of publishing and receiving events and data.
44
45 \note Although the Publish Subscribe plugin simplifies the process of creating
46 and receiving notifications, various platforms may require special actions
47 to be taken before the Publisher and Subscribers are created.
48
49 \section2 Publisher
50
51 The \l ValueSpacePublisher element allows us to publish key-value pairs
52 of data to a known path. The "known path" is really the "key" of a key/value
53 pair. The path has the form of a directory structure
54 path with the keys acting as files at the end of the path. The process
55 is that the developer declares a \l ValueSpacePublisher element and then
56 with a given path defines a list of known keys. For example
57
58 \qml
59 ValueSpacePublisher {
60 id: battery
61 path: "/power/battery"
62 keys: ["charge", "charging"]
63 }
64 \endqml
65
66 To publish a value the key need only be set to the value. Here we see
67 that the key is expressed as the last name in the path with dot notation
68 followed by the key name.
69
70 \qml
71 battery.charge = 50
72 battery.charging = true
73 \endqml
74
75 \section2 Subscriber
76
77 The \l ValueSpaceSubscriber element also defines the path to the
78 key/value. For each \e key a different \l ValueSpaceSubscriber needs to be
79 declared. In the above example where we used the keys 'charge' and 'charging'
80 we will need subscribers for each key
81
82 \snippet ../../examples/publishsubscribe/battery-charge/battery-subscriber/battery-subscriber.qml 0
83
84 Now the values being published can be read and used
85
86 \snippet ../../examples/publishsubscribe/battery-charge/battery-subscriber/battery-subscriber.qml 2
87
88 \section1 QML Elements
89 \annotatedlist qml-publishsubscribe
90
91 \section1 Examples
92 \list
93 \li \l {battery-charge}{Accessing Publish and Subscribe from QML}
94 \endlist
95 */