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-index.qdoc
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qtbluetooth-index.html
6\title Qt Bluetooth
7\brief Qt Bluetooth enables connectivity between Bluetooth enabled devices.
8\ingroup technology-apis
9
10The Bluetooth API provides connectivity between Bluetooth enabled devices.
11
12Currently, the API is supported on the following platforms:
13
14\table
15\header
16 \li API Feature
17 \li \l {Qt for Android}{Android}
18 \li \l {Qt for HarmonyOS}{HarmonyOS}
19 \li \l {Qt for iOS}{iOS}
20 \li \l {Qt for Linux}{Linux (BlueZ 5.x)}
21 \li \l {Qt for macOS}{\macos}
22 \li \l {Qt for Windows}{Windows}
23\row
24 \li Classic Bluetooth
25 \li x
26 \li x
27 \li
28 \li x
29 \li x
30 \li x
31\row
32 \li Bluetooth LE Central
33 \li x
34 \li
35 \li x
36 \li x
37 \li x
38 \li x
39\row
40 \li Bluetooth LE Peripheral
41 \li x
42 \li
43 \li x
44 \li x
45 \li x
46 \li
47\endtable
48
49\section1 Overview
50
51Bluetooth is a short-range (less than 100 meters) wireless technology. It
52has a data transfer rate of 2.1 Mbps, which makes it ideal
53for transferring data between devices. Bluetooth connectivity is based on
54basic device management, such as scanning for devices, gathering information
55about them, and exchanging data between them.
56
57Qt Bluetooth supports Bluetooth Low Energy development for client/central role
58use cases. Further details can be found in the
59\l {Bluetooth Low Energy Overview}{Bluetooth Low Energy Overview} section.
60
61\section1 Using the Module
62
63\include {module-use.qdocinc} {using the c++ api}
64
65\section2 Building with CMake
66
67\include {module-use.qdocinc} {building with cmake} {Bluetooth}
68
69\section2 Building with qmake
70
71\include {module-use.qdocinc} {building_with_qmake} {bluetooth}
72
73\section1 Permissions
74
75Starting from Qt 6.6, the Qt Bluetooth module uses new \l QPermission API
76to handle \l {QBluetoothPermission}{Bluetooth} permissions. This means that Qt
77itself no longer queries for these permissions, so this needs to be done
78directly from the client application.
79
80Please refer to the \l {Application Permissions} page for an example of how
81to integrate the new \l QPermission API into the application.
82
83\section1 Related Information
84
85\section2 Building Qt Bluetooth
86
87Even though the module can be built for all Qt platforms, the module is not
88ported to all of them. Non-supported platforms employ a dummy backend that is
89automatically selected when the platform is not supported. The dummy backend
90reports appropriate error messages and values, which enables you to detect at
91runtime that the current platform is not supported. The dummy backend is also
92selected on Linux if BlueZ development headers are not found during build time
93or Qt was built without Qt D-Bus support.
94
95The usage of the dummy backend is highlighted via an appropriate warning while building and running.
96
97\section3 Linux Specific
98
99Since Qt 6.5 the Linux peripheral support has two backend alternatives:
100BlueZ DBus and Bluetooth Kernel API. The DBus backend is the default
101backend since Qt 6.7.
102
103BlueZ DBus is the newer BlueZ stack and possibly the eventual successor of the
104older Kernel API. It is a bit more limited in terms of features, but in a
105typical usage this should not matter. One notable benefit of using the DBus
106backend is that the user process no longer needs to have the
107\e CAP_NET_ADMIN capability (for example by running as \c root user).
108
109The DBus backend requires BlueZ version 5.56 or higher, and that it provides
110the needed DBus APIs. If these requirements are not met, Qt automatically
111falls back to the Bluetooth Kernel API backend.
112
113The older kernel backend can also be selected manually by setting the
114\e QT_BLUETOOTH_USE_KERNEL_PERIPHERAL environment variable.
115
116\section3 \macos Specific
117The Bluetooth API on \macos requires a certain type of event dispatcher
118that in Qt causes a dependency to \l QGuiApplication. However, you can set the
119environment variable \c {QT_EVENT_DISPATCHER_CORE_FOUNDATION=1} to circumvent
120this issue.
121
122Applications that don't use Classic Bluetooth will find a subset of QtBluetooth
123is available, as CoreBluetooth (Bluetooth LE) don't require \l QApplication or
124\l QGuiApplication.
125
126\section2 Articles and Guides
127\list
128 \li \l {Qt Bluetooth Overview}{Classic Bluetooth Overview}
129 \li \l {Bluetooth Low Energy Overview}
130\endlist
131
132\section2 Reference
133\list
134 \li \l {Qt Bluetooth C++ Classes}{C++ Classes}
135\endlist
136
137\section2 Logging Categories
138
139The \l QtBluetooth module exports the following
140\l {Configuring Categories}{logging categories}:
141
142\table
143\header
144 \li Logging Category
145 \li Description
146\row
147 \li qt.bluetooth
148 \li Enables logging of cross platform code path in QtBluetooth
149\row
150 \li qt.bluetooth.android
151 \li Enables logging of the \l {Qt for Android} {Android} implementation
152\row
153 \li qt.bluetooth.bluez
154 \li Enables logging of the BLuez/Linux implementation
155\row
156 \li qt.bluetooth.ios
157 \li Enables logging of the \l {Qt for iOS} {iOS} implementation
158\row
159 \li qt.bluetooth.ohos
160 \li Enables logging of the \l {Qt for HarmonyOS} {HarmonyOS} implementation
161\row
162 \li qt.bluetooth.osx
163 \li Enables logging of the \l {Qt for macOS} {macOS} implementation
164\row
165 \li qt.bluetooth.windows
166 \li Enables logging of the \l {Qt for Windows} {Windows} implementation
167\endtable
168
169Logging categories enable additional warning and debug output for QtBluetooth.
170More detailed information about logging is found in \l QLoggingCategory. A
171quick way to enable all QtBluetooth logging is to add the following line to the
172\c main() function:
173
174\code
175 QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true"));
176\endcode
177
178\section2 Examples
179\list
180 \li QML
181 \list
182 \li \l {heartrate-game}{Bluetooth Low Energy Heart Rate Game}
183 \li \l {heartrate-server}{Bluetooth Low Energy Heart Rate Server}
184 \li \l {lowenergyscanner}{Bluetooth Low Energy Scanner}
185 \endlist
186 \li C++
187 \list
188 \li \l {btchat}{Bluetooth Chat}
189 \endlist
190\endlist
191
192\section1 Module Evolution
193
194\l{Changes to Qt Bluetooth} lists important changes in the module
195API and functionality that were done for the Qt 6 series of Qt.
196
197\section1 Licenses and Attributions
198
199Qt Bluetooth is available under commercial licenses from \l{The Qt Company}.
200In addition, it is available under the
201\l{GNU Lesser General Public License, version 3}, or
202the \l{GNU General Public License, version 2}.
203See \l{Qt Licensing} for further details.
204
205On Linux, Qt Bluetooth uses a separate executable, \c sdpscanner,
206to integrate with the official Linux bluetooth protocol stack
207BlueZ. BlueZ is available under the \l{GNU General Public License,
208version 2}.
209
210\annotatedlist attributions-qtbluetooth
211*/