summaryrefslogtreecommitdiffstats
path: root/doc/src/bluetooth-overview.qdoc
blob: d51fd2a7952e889e5f38c588c2148559872cf3e1 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the documentation of the Qt local connectivty modules.
**
** $QT_BEGIN_LICENSE:FDL$
** GNU Free Documentation License
** 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.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms
** and conditions contained in a signed written agreement between you
** and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
\ingroup technology-apis
\title Qt Bluetooth Overview
\page qtbluetooth-overview.html
\brief The Qt Bluetooth API enables connectivity with other Bluetooth enabled devices.

\tableofcontents

    With the Qt Bluetooth API typical use cases are:

        \list
        \li Retrieve information about the local Bluetooth device.
        \li Scan for other Bluetooth devices in range and retrieve information about them.
        \li Push files to remote devices using the OBEX Object Push Profile (OPP).
        \li Connect to remote devices through a RFCOMM channel using the Serial Port Profile (SPP).
        \li Create a RFCOMM server that allows incoming connections using SPP.
        \endlist

    The following sections describe how to use the Qt Bluetooth C++ API classes
    for the above use cases.

    \section1 Retrieving Local Device Information

    The Qt Bluetooth API has three main purposes. The first one is to
    obtain local and remote device information. The first steps in retrieving device information is
    to check if Bluetooth is available on the device and read the local device address and name. The
    QBluetoothLocalDevice is the one to provide all of this information. Additionally you can use it
    to turn Bluetooth on and off and set the visibility on the device.

    \snippet ../doc/src/snippets/doc_src_qtbluetooth.cpp turningon

    \section1 Scanning for Bluetooth Devices

    Similar to the QBluetoothLocalDevice, the API offers QBluetoothDeviceInfo which provides
    that information for remote devices. While you can just create QBluetoothDeviceInfo objects on
    your own and fill them with data, the easier way is to use the QBluetoothDeviceDiscoveryAgent to
    start an automated search for visible Bluetooth devices within the connectable range.

    \snippet ../doc/src/snippets/doc_src_qtbluetooth.cpp discovery

    \section1 Pushing Files to Remote Devices

    Once the desired device is found, there are two main use cases provided by Qt Bluetooth. The
    simpler is to send files via the Obex Object Push Profile (OPP). As the name describes, this
    profile can only push files from one device to another but not pull files or browse the remote
    file system. Because of this limitation, this profile does not require the two devices to be
    paired before exchanging data. To push files to remote devices, create a
    QBluetoothTransferRequest and ask the QBluetoothTransferManager to push the file contained in
    the request by calling the put() function.

    \snippet ../doc/src/snippets/doc_src_qtbluetooth.cpp sendfile

    \section1 Exchanging Data Between Devices

    The more flexible approach to do communication between two Bluetooth enabled devices, is to
    create a virtual serial port connection and freely exchange data over that connection. This can
    be done by the Serial Port Profile (SPP). The Serial Port Profile emulates a serial connection
    over the Bluetooth transport protocol RFCOMM.

    To be able to create SPP connections, you need to register a Server one one device by using
    QRfcommServer.

    \snippet ../examples/btchat/chatserver.cpp Create the server

    Connect to this server from another device playing the client role by using a
    QBluetoothSocket.

    \snippet ../examples/btchat/chatclient.cpp startClient

    Using such a connection allows to exchange any form of data in both directions.
    It is perfectly suited for use cases like gaming or syncing the state between two instances of
    an application on two devices. For more detailed descriptions on how to configure the server
    and client, please refer to the detailed description sections in the QRfcommServer and
    QBluetoothSocket classes. A good example to start with SPP is the \l{btchat}{Bluetooth Chat}
    example.

*/