summaryrefslogtreecommitdiffstats
path: root/examples/bluetooth/chat/doc/src/chat.qdoc
blob: 5f61fd74d4c8b5171fad31469ad034d6926da45b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt local connectivty modules.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file.  Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \example chat
    \title Bluetooth QML Chat Example
    \brief An example demonstrating communication through Bluetooth QML API.

    \e {Bluetooth QML Chat} example shows how to use the \l{Qt Bluetooth} QML API to communicate
    with another application on a remote device using Bluetooth.

    \image chat-view.png

    The Bluetooth QML Chat example implements a simple chat program between two parties. The
    application acts as client and attempts to connect to a Bluetooth socket server. It uses
    the \l BluetoothDiscoveryModel type to find the server and \l BluetoothSocket type to
    facilitate the data exchange.

    \include examples-run.qdocinc

    The example only works in connection with the \l {btchat}{Bluetooth Chat Example}.
    The Bluetooth Chat example launches the chat service and advertises it via the
    Bluetooth SDP protocol. It is important that the device running the Bluetooth Chat
    example actively advertises its SDP services.
    This can be checked using the \l QBluetoothLocalDevice::hostMode property.

    \section1 Interacting with the Server

    The example application immediately starts the service discovery using the
    \l BluetoothDiscoveryModel type:

    \snippet chat/chat.qml BtDiscoveryModel-1
    \snippet chat/chat.qml BtDiscoveryModel-3

    The \l {BluetoothDiscoveryModel::uuidFilter}{uuidFilter} property is used to only search for
    the chat server UUID and the \l {BluetoothDiscoveryModel::running}{running}
    property activates the search. Once a service with a matching UUID is found the model emits the
    \l {BluetoothDiscoveryModel::serviceDiscovered}{serviceDiscovered(BluetoothService)} signal.

    \snippet chat/chat.qml BtDiscoveryModel-2

    The \l BluetoothService type encapsulates the details of the found chat server, such as the
    \l {BluetoothService::serviceName}{name} and \l {BluetoothService::serviceDescription}{description} of the
    service, as well as the \l{BluetoothService::deviceName}{name} and \l {BluetoothService::deviceAddress}{address}
    of the Bluetooth device offering the chat server. It is passed to the \l BluetoothSocket
    to establish the connection.

    Once the connection is established the chat information is:
    \snippet chat/chat.qml BluetoothSocket-1
    \snippet chat/chat.qml BluetoothSocket-2

    The payload is received via the \l {BluetoothSocket::stringData}{stringData} property:

    \snippet chat/chat.qml BluetoothSocket-3
    \snippet chat/chat.qml BluetoothSocket-4

    And sent by setting the same property:

    \snippet chat/chat.qml BluetoothSocket-5
*/