Debian Codegraph @

doc/src/publishsubscribe/examples/publish-subscribe.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 \example publish-subscribe
30 \ingroup publishsubscribe-examples
31 \title Publish and Subscribe Example
32
33 The Publish and Subscribe example shows how to use the Qt Publish and Subscribe API to
34 publish and retrieve values from the platforms Publish and Subscribe system.
35
36 This example program can act as either a publisher of Value Space content, or a subscriber of
37 Value Space content, or both. It can also optionally act as the Value Space Manager. The
38 behavior is selected by passing a combination of three optional command line parameters when
39 starting the program. If no parameters are supplied the program defaults to acting as both a
40 publisher and a subscriber.
41
42 \table
43 \header
44 \li Parameter
45 \li Description
46 \row
47 \li -publisher
48 \li Publish values in the Value Space and create a dialog to control those values
49 directly.
50 \row
51 \li -subscriber
52 \li Create a dialog to view Value Space items.
53 \endtable
54
55 \section2 Publisher
56
57 When acting as a publisher of Value Space content the program creates a PublisherDialog. This
58 dialog contains a widget for setting the base path of the QValueSpacePublisher and
59 widgets for setting the value of the three fixed attributes 'intValue', 'stringValue' and
60 'byteArrayValue'.
61
62 \image publish-subscribe-publisher.png
63
64 We declare the slots which we will use to respond to user input in the dialog.
65
66 \snippet publish-subscribe/publisherdialog.h 0
67
68 And connect them to signals from the widgets in the constructor.
69
70 \snippet publish-subscribe/publisherdialog.cpp 1
71
72 To publish values in the Value Space we first need to create a QValueSpacePublisher. This is
73 done in the \c {createNewObject()} slot, which is also used to handle changes in the base path.
74 After the object is constructed we publish the initial values by explicitly calling the other
75 slots.
76
77 \snippet publish-subscribe/publisherdialog.cpp 2
78
79 We use QValueSpacePublisher::setValue() to set the values in response to dialog input.
80
81 \snippet publish-subscribe/publisherdialog.cpp 0
82
83 As a final step in the constructor we explicitly call the \c {createNewObject()} slot to create
84 an initial QValueSpacePublisher.
85
86 \snippet publish-subscribe/publisherdialog.cpp 3
87
88 \section2 Subscriber
89
90 When acting as a subscriber of Value Space content the program creates a SubscriberDialog.
91 This dialog contains a widget for setting the base path of the QValueSpaceSubscriber and a
92 table for displaying all of the values directly under base path in the Value Space.
93
94 \image publish-subscribe-subscriber.png
95
96 We declare two slots to propagate values from the Value Space to the dialog in response to
97 change notifications from QValueSpaceSubscriber.
98
99 \snippet publish-subscribe/subscriberdialog.h 0
100
101 To read values from the Value Space we first create a QValueSpaceSubscriber and connect to the
102 \c {contentsChanged()} signal.
103
104 We explicitly call our \c {subscriberChanged()} slot to populate the table with the initial
105 values.
106
107 \snippet publish-subscribe/subscriberdialog.cpp 0
108
109 In response to the \c {contentsChanged()} signal we update all the values in the table.
110
111 \snippet publish-subscribe/subscriberdialog.cpp 1
112 */