Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qlowenergycontroller.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QLOWENERGYCONTROLLER_H
5#define QLOWENERGYCONTROLLER_H
6
7#include <QtCore/QObject>
8#include <QtBluetooth/QBluetoothAddress>
9#include <QtBluetooth/QBluetoothDeviceInfo>
10#include <QtBluetooth/QBluetoothUuid>
11#include <QtBluetooth/QLowEnergyAdvertisingData>
12#include <QtBluetooth/QLowEnergyConnectionParameters>
13#include <QtBluetooth/QLowEnergyService>
14
16
20
21class Q_BLUETOOTH_EXPORT QLowEnergyController : public QObject
22{
24public:
39
49 Q_ENUM(ControllerState)
50
52 PublicAddress = 0,
53 RandomAddress
54 };
55 Q_ENUM(RemoteAddressType)
56
57 enum Role { CentralRole, PeripheralRole };
58 Q_ENUM(Role)
59
60 static QLowEnergyController *createCentral(const QBluetoothDeviceInfo &remoteDevice,
61 QObject *parent = nullptr);
62 static QLowEnergyController *createCentral(const QBluetoothDeviceInfo &remoteDevice,
63 const QBluetoothAddress &localDevice,
64 QObject *parent = nullptr);
65 static QLowEnergyController *createPeripheral(const QBluetoothAddress &localDevice,
66 QObject *parent = nullptr);
67 static QLowEnergyController *createPeripheral(QObject *parent = nullptr);
68
69 // TODO: Allow to set connection timeout (disconnect when no data has been exchanged for n seconds).
70
72
73 QBluetoothAddress localAddress() const;
74 QBluetoothAddress remoteAddress() const;
75 QBluetoothUuid remoteDeviceUuid() const;
76
77 QString remoteName() const;
78
79 ControllerState state() const;
80
81 // TODO Qt6 remove this property. It is not longer needed when using Bluez DBus backend
82 RemoteAddressType remoteAddressType() const;
83 void setRemoteAddressType(RemoteAddressType type);
84
85 void connectToDevice();
86 void disconnectFromDevice();
87
88 void discoverServices();
89 QList<QBluetoothUuid> services() const;
90 QLowEnergyService *createServiceObject(const QBluetoothUuid &service, QObject *parent = nullptr);
91
92 void startAdvertising(const QLowEnergyAdvertisingParameters &parameters,
93 const QLowEnergyAdvertisingData &advertisingData,
94 const QLowEnergyAdvertisingData &scanResponseData = QLowEnergyAdvertisingData());
95 void stopAdvertising();
96
97 QLowEnergyService *addService(const QLowEnergyServiceData &service, QObject *parent = nullptr);
98
99 void requestConnectionUpdate(const QLowEnergyConnectionParameters &parameters);
100
101 Error error() const;
102 QString errorString() const;
103
104 Role role() const;
105
106 int mtu() const;
107 void readRssi();
108
110 void connected();
114 void mtuChanged(int mtu);
116
117 void serviceDiscovered(const QBluetoothUuid &newService);
120
121
122private:
123 // peripheral role ctor
124 explicit QLowEnergyController(const QBluetoothAddress &localDevice, QObject *parent = nullptr);
125
126 // central role ctors
127 explicit QLowEnergyController(const QBluetoothDeviceInfo &remoteDevice,
128 const QBluetoothAddress &localDevice,
129 QObject *parent = nullptr);
130
131
132 Q_DECLARE_PRIVATE(QLowEnergyController)
134};
135
137
139 Q_BLUETOOTH_EXPORT)
141 QLowEnergyController__ControllerState,
142 Q_BLUETOOTH_EXPORT)
144 QLowEnergyController__RemoteAddressType,
145 Q_BLUETOOTH_EXPORT)
147 Q_BLUETOOTH_EXPORT)
148
149#endif // QLOWENERGYCONTROLLER_H
quint8 rssi
std::vector< ObjCStrongReference< CBMutableService > > services
\inmodule QtBluetooth
\inmodule QtBluetooth
\inmodule QtBluetooth
The QLowEnergyAdvertisingData class represents the data to be broadcast during Bluetooth Low Energy a...
The QLowEnergyAdvertisingParameters class represents the parameters used for Bluetooth Low Energy adv...
The QLowEnergyConnectionParameters class is used when requesting or reporting an update of the parame...
\inmodule QtBluetooth
RemoteAddressType
Indicates what type of Bluetooth address the remote device uses.
ControllerState
Indicates the state of the controller object.
void connected()
This signal is emitted when the controller successfully connects to the remote Low Energy device (if ...
void rssiRead(qint16 rssi)
This signal is emitted after successful read of RSSI (received signal strength indicator) for a conne...
Role
Indicates the role of the controller object.
void errorOccurred(QLowEnergyController::Error newError)
This signal is emitted when an error occurs.
void connectionUpdated(const QLowEnergyConnectionParameters &parameters)
This signal is emitted when the connection parameters change.
Error
Indicates all possible error conditions found during the controller's existence.
void disconnected()
This signal is emitted when the controller disconnects from the remote Low Energy device or vice vers...
void stateChanged(QLowEnergyController::ControllerState state)
This signal is emitted when the controller's state changes.
void serviceDiscovered(const QBluetoothUuid &newService)
This signal is emitted each time a new service is discovered.
void discoveryFinished()
This signal is emitted when the running service discovery finishes.
void mtuChanged(int mtu)
This signal is emitted as a result of a successful MTU change.
The QLowEnergyServiceData class is used to set up GATT service data. \inmodule QtBluetooth.
\inmodule QtBluetooth
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
else opt state
[0]
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
#define QT_DECL_METATYPE_EXTERN_TAGGED(TYPE, TAG, EXPORT)
Definition qmetatype.h:1376
GLenum type
#define Q_ENUM(x)
#define Q_OBJECT
#define Q_SIGNALS
short qint16
Definition qtypes.h:47