Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
bluetooth-overview.qdoc
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\ingroup technology-apis
6\title Qt Bluetooth Overview
7\page qtbluetooth-overview.html
8\brief The Qt Bluetooth API enables connectivity with other regular Bluetooth
9 and Bluetooth Low Energy enabled devices.
10
11 With the Qt Bluetooth API typical use cases are:
12
13 \list
14 \li Retrieve information about the local Bluetooth device.
15 \li Scan for other Bluetooth devices in range and retrieve information about them.
16 \li Push files to remote devices using the OBEX Object Push Profile (OPP)
17 \li Connect to remote devices through a RFCOMM channel using the Serial Port Profile (SPP).
18 \li Create a RFCOMM server that allows incoming connections using SPP.
19 \li Retrieve specification about Bluetooth Low Energy device.
20 \li Connect to Bluetooth Low Energy device.
21 \li Receive advertisement from Bluetooth Low Energy device.
22 \endlist
23
24 Note that the Object Push Profile is not supported on Android and Windows.
25
26 \note Parts of RFCOMM functionality cannot be configured by Qt on
27 Windows. A service's \l {QBluetoothServiceInfo::}{ServiceClassIds} and
28 \l {QBluetoothServiceInfo::}{ProtocolDescriptorList} are filled
29 automatically. Therefore, registering a service with custom values for
30 these fields might not yield the expected result on Windows.
31
32 \note The Received Signal Strength Indicator (RSSI), as well as
33 the Manufacturer Specific Data advertised by Bluetooth LE devices are
34 not supported by the Win32 backend. Also, it is only possible to find
35 devices that have been previously paired through Windows Settings.
36
37 The following sections describe how to use the Qt Bluetooth C++ API classes
38 for the above use cases.
39
40 \section1 Retrieving Local Device Information
41
42 The Qt Bluetooth API has three main purposes. The first one is to
43 obtain local and remote device information. The first steps in retrieving device information are
44 to check if Bluetooth is available on the device and read the local device address and name.
45 QBluetoothLocalDevice is the class that provides all of this information. Additionally you can use it
46 to turn Bluetooth on/off, set the visibility of the device and determine the current connections.
47
48 \snippet doc_src_qtbluetooth.cpp turningon
49
50 \section1 Scanning for Bluetooth Devices
51
52 Similar to the QBluetoothLocalDevice, the API offers QBluetoothDeviceInfo which provides
53 similar information for remote devices. Although you can just create QBluetoothDeviceInfo objects on
54 your own and fill them with data, the easier way is to use the QBluetoothDeviceDiscoveryAgent to
55 start an automated search for visible Bluetooth devices within the connectable range.
56
57 \snippet doc_src_qtbluetooth.cpp device_discovery
58
59 \section1 Exchanging Data Between Devices
60
61 The more flexible approach for communication between two Bluetooth enabled devices, is to
62 create a virtual serial port connection and freely exchange data over that connection. This can
63 be done by the Serial Port Profile (SPP). The Serial Port Profile emulates a serial connection
64 over the Bluetooth transport protocol RFCOMM.
65
66 To be able to receive incoming SPP connections, you need to listen to incoming connections using
67 \l QBluetoothServer.
68
69 \snippet btchat/chatserver.cpp Create the server
70
71 Connect to this server from another device playing the client role by using a
72 QBluetoothSocket:
73
74 \snippet btchat/chatclient.cpp startClient
75
76 Using such a connection allows to exchange any form of data in both directions.
77 It is perfectly suited for gaming or for syncing the state between two instances of
78 an application on two devices. For more detailed descriptions on how to configure the server
79 and client, please refer to the detailed description sections in the \l QBluetoothServer and
80 \l QBluetoothSocket classes. A good example to start with SPP is the \l{btchat}{Bluetooth Chat}
81 example.
82
83 \section1 Bluetooth Low Energy
84
85 Bluetooth Low Energy, also known as Bluetooth Smart, is a new technology enabling
86 devices with low energy consumption to communicate with each other. More details about
87 this technology and the related Qt APIs can be found in the \l {Bluetooth Low Energy Overview}.
88*/