![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtBluetooth More...
#include <qlowenergycontroller.h>
Public Types | |
enum | Error { NoError , UnknownError , UnknownRemoteDeviceError , NetworkError , InvalidBluetoothAdapterError , ConnectionError , AdvertisingError , RemoteHostClosedError , AuthorizationError , MissingPermissionsError , RssiReadError } |
Indicates all possible error conditions found during the controller's existence. More... | |
enum | ControllerState { UnconnectedState = 0 , ConnectingState , ConnectedState , DiscoveringState , DiscoveredState , ClosingState , AdvertisingState } |
Indicates the state of the controller object. More... | |
enum | RemoteAddressType { PublicAddress = 0 , RandomAddress } |
Indicates what type of Bluetooth address the remote device uses. More... | |
enum | Role { CentralRole , PeripheralRole } |
Indicates the role of the controller object. More... | |
Signals | |
void | connected () |
This signal is emitted when the controller successfully connects to the remote Low Energy device (if the controller is in the \l CentralRole) or if a remote Low Energy device connected to the controller (if the controller is in the \l PeripheralRole). | |
void | disconnected () |
This signal is emitted when the controller disconnects from the remote Low Energy device or vice versa. | |
void | stateChanged (QLowEnergyController::ControllerState state) |
This signal is emitted when the controller's state changes. | |
void | errorOccurred (QLowEnergyController::Error newError) |
This signal is emitted when an error occurs. | |
void | mtuChanged (int mtu) |
This signal is emitted as a result of a successful MTU change. | |
void | rssiRead (qint16 rssi) |
This signal is emitted after successful read of RSSI (received signal strength indicator) for a connected remote device. | |
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 | connectionUpdated (const QLowEnergyConnectionParameters ¶meters) |
This signal is emitted when the connection parameters change. | |
![]() | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
Public Member Functions | |
~QLowEnergyController () | |
Destroys the QLowEnergyController instance. | |
QBluetoothAddress | localAddress () const |
Returns the address of the local Bluetooth adapter being used for the communication. | |
QBluetoothAddress | remoteAddress () const |
Returns the address of the remote Bluetooth Low Energy device. | |
QBluetoothUuid | remoteDeviceUuid () const |
Returns the unique identifier of the remote Bluetooth Low Energy device. | |
QString | remoteName () const |
Returns the name of the remote Bluetooth Low Energy device, if the controller is in the \l CentralRole. | |
ControllerState | state () const |
Returns the current state of the controller. | |
RemoteAddressType | remoteAddressType () const |
Returns the type of \l remoteAddress(). | |
void | setRemoteAddressType (RemoteAddressType type) |
Sets the remote address type. | |
void | connectToDevice () |
Connects to the remote Bluetooth Low Energy device. | |
void | disconnectFromDevice () |
Disconnects from the remote device. | |
void | discoverServices () |
Initiates the service discovery process. | |
QList< QBluetoothUuid > | services () const |
Returns the list of services offered by the remote device, if the controller is in the \l CentralRole. | |
QLowEnergyService * | createServiceObject (const QBluetoothUuid &service, QObject *parent=nullptr) |
Creates an instance of the service represented by serviceUuid. | |
void | startAdvertising (const QLowEnergyAdvertisingParameters ¶meters, const QLowEnergyAdvertisingData &advertisingData, const QLowEnergyAdvertisingData &scanResponseData=QLowEnergyAdvertisingData()) |
Starts advertising the data given in advertisingData and scanResponseData, using the parameters set in parameters. | |
void | stopAdvertising () |
Stops advertising, if this object is currently in the advertising state. | |
QLowEnergyService * | addService (const QLowEnergyServiceData &service, QObject *parent=nullptr) |
Constructs and returns a \l QLowEnergyService object with parent from service. | |
void | requestConnectionUpdate (const QLowEnergyConnectionParameters ¶meters) |
Requests the controller to update the connection according to parameters. | |
Error | error () const |
Returns the last occurred error or \l NoError. | |
QString | errorString () const |
Returns a textual representation of the last occurred error. | |
Role | role () const |
Returns the role that this controller object is in. | |
int | mtu () const |
Returns the MTU size. | |
void | readRssi () |
readRssi() reads RSSI (received signal strength indicator) for a connected remote device. | |
![]() | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Static Public Member Functions | |
static QLowEnergyController * | createCentral (const QBluetoothDeviceInfo &remoteDevice, QObject *parent=nullptr) |
Returns a new object of this class that is in the \l CentralRole and has the parent object parent. | |
static QLowEnergyController * | createCentral (const QBluetoothDeviceInfo &remoteDevice, const QBluetoothAddress &localDevice, QObject *parent=nullptr) |
Returns a new instance of this class with parent. | |
static QLowEnergyController * | createPeripheral (const QBluetoothAddress &localDevice, QObject *parent=nullptr) |
Returns a new object of this class that is in the \l PeripheralRole and has the parent object parent and is using localDevice. | |
static QLowEnergyController * | createPeripheral (QObject *parent=nullptr) |
Returns a new object of this class that is in the \l PeripheralRole and has the parent object parent. | |
![]() | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
Additional Inherited Members | |
![]() | |
void | deleteLater () |
\threadsafe | |
![]() | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
![]() | |
QScopedPointer< QObjectData > | d_ptr |
![]() | |
QString | objectName |
the name of this object | |
![]() | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
\inmodule QtBluetooth
The QLowEnergyController class provides access to Bluetooth Low Energy Devices.
QLowEnergyController acts as the entry point for Bluetooth Low Energy development.
Bluetooth Low Energy defines two types of devices; the peripheral and the central. Each role performs a different task. The peripheral device provides data which is utilized by central devices. An example might be a humidity sensor which measures the moisture in a winter garden. A device such as a mobile phone might read the sensor's value and display it to the user in the greater context of all sensors in the same environment. In this case the sensor is the peripheral device and the mobile phone acts as the central device.
A controller in the central role is created via the \l createCentral() factory method. Such an object essentially acts as a placeholder towards a remote Low Energy peripheral device, enabling features such as service discovery and state tracking.
After having created a controller object in the central role, the first step is to establish a connection via \l connectToDevice(). Once the connection has been established, the controller's \l state() changes to \l QLowEnergyController::ConnectedState and the \l connected() signal is emitted. It is important to mention that some platforms such as a BlueZ based Linux cannot maintain two connected instances of \l QLowEnergyController to the same remote device. In such cases the second call to \l connectToDevice() may fail. This limitation may disappear at some stage in the future. The \l disconnectFromDevice() function is used to break the existing connection.
The second step after establishing the connection is to discover the services offered by the remote peripheral device. This process is started via \l discoverServices() and has finished once the \l discoveryFinished() signal has been emitted. The discovered services can be enumerated via \l services().
The last step is to create service objects. The \l createServiceObject() function acts as factory for each service object and expects the service UUID as parameter. The calling context should take ownership of the returned \l QLowEnergyService instance.
Any \l QLowEnergyService, \l QLowEnergyCharacteristic or \l QLowEnergyDescriptor instance which is later created from this controller's connection becomes invalid as soon as the controller disconnects from the remote Bluetooth Low Energy device.
A controller in the peripheral role is created via the \l createPeripheral() factory method. Such an object acts as a peripheral device itself, enabling features such as advertising services and allowing clients to get notified about changes to characteristic values.
After having created a controller object in the peripheral role, the first step is to populate the set of GATT services offered to client devices via calls to \l addService(). Afterwards, one would call \l startAdvertising() to let the device broadcast some data and, depending on the type of advertising being done, also listen for incoming connections from GATT clients.
Definition at line 21 of file qlowenergycontroller.h.
Indicates the state of the controller object.
\value UnconnectedState The controller is not connected to a remote device. \value ConnectingState The controller is attempting to connect to a remote device. \value ConnectedState The controller is connected to a remote device. \value DiscoveringState The controller is retrieving the list of services offered by the remote device. \value DiscoveredState The controller has discovered all services offered by the remote device. \value ClosingState The controller is about to be disconnected from the remote device. \value [since 5.7] AdvertisingState The controller is currently advertising data.
Enumerator | |
---|---|
UnconnectedState | |
ConnectingState | |
ConnectedState | |
DiscoveringState | |
DiscoveredState | |
ClosingState | |
AdvertisingState |
Definition at line 40 of file qlowenergycontroller.h.
Indicates all possible error conditions found during the controller's existence.
\value NoError No error has occurred. \value UnknownError An unknown error has occurred. \value UnknownRemoteDeviceError The remote Bluetooth Low Energy device with the address passed to the constructor of this class cannot be found. \value NetworkError The attempt to read from or write to the remote device failed. \value InvalidBluetoothAdapterError The local Bluetooth device with the address passed to the constructor of this class cannot be found or there is no local Bluetooth device. \value [since 5.5] ConnectionError The attempt to connect to the remote device failed. \value [since 5.7] AdvertisingError The attempt to start advertising failed. \value [since 5.10] RemoteHostClosedError The remote device closed the connection. \value [since 5.14] AuthorizationError The local Bluetooth device closed the connection due to insufficient authorization. \value [since 6.4] MissingPermissionsError The operating system requests permissions which were not granted by the user. \value [since 6.5] RssiReadError An attempt to read RSSI (received signal strength indicator) of a remote device finished with error.
Definition at line 25 of file qlowenergycontroller.h.
Indicates what type of Bluetooth address the remote device uses.
\value PublicAddress The remote device uses a public Bluetooth address. \value RandomAddress A random address is a Bluetooth Low Energy security feature. Peripherals using such addresses may frequently change their Bluetooth address. This information is needed when trying to connect to a peripheral.
Enumerator | |
---|---|
PublicAddress | |
RandomAddress |
Definition at line 51 of file qlowenergycontroller.h.
Indicates the role of the controller object.
\value CentralRole The controller acts as a client interacting with a remote device which is in the peripheral role. The controller can initiate connections, discover services and read and write characteristics. \value PeripheralRole The controller can be used to advertise services and handle incoming connections and client requests, acting as a GATT server. A remote device connected to the controller is in the central role.
Enumerator | |
---|---|
CentralRole | |
PeripheralRole |
Definition at line 57 of file qlowenergycontroller.h.
QLowEnergyController::~QLowEnergyController | ( | ) |
Destroys the QLowEnergyController instance.
Definition at line 501 of file qlowenergycontroller.cpp.
References disconnectFromDevice().
QLowEnergyService * QLowEnergyController::addService | ( | const QLowEnergyServiceData & | service, |
QObject * | parent = nullptr |
||
) |
Constructs and returns a \l QLowEnergyService object with parent from service.
The controller must be in the \l PeripheralRole and in the \l UnconnectedState. The service object must be valid.
Definition at line 826 of file qlowenergycontroller.cpp.
References QBluetoothPermission::Access, d, ensureAndroidPermission(), QObject::parent(), PeripheralRole, qCWarning, role(), QObject::setParent(), state(), and UnconnectedState.
|
signal |
This signal is emitted when the controller successfully connects to the remote Low Energy device (if the controller is in the \l CentralRole) or if a remote Low Energy device connected to the controller (if the controller is in the \l PeripheralRole).
On iOS, macOS, and Android this signal is not reliable if the controller is in the \l PeripheralRole. On iOS and macOS the controller only guesses that some central connected to our peripheral as soon as this central tries to write/read a characteristic/descriptor. On Android the controller monitors all connected GATT devices. On Linux BlueZ DBus peripheral backend the remote is considered connected when it first reads/writes a characteristic or a descriptor.
|
signal |
This signal is emitted when the connection parameters change.
This can happen as a result of calling \l requestConnectionUpdate() or due to other reasons, for instance because the other side of the connection requested new parameters. The new values can be retrieved from newParameters.
void QLowEnergyController::connectToDevice | ( | ) |
Connects to the remote Bluetooth Low Energy device.
This function does nothing if the controller's \l state() is not equal to \l UnconnectedState. The \l connected() signal is emitted once the connection is successfully established.
On Linux/BlueZ systems, it is not possible to connect to the same remote device using two instances of this class. The second call to this function may fail with an error. This limitation may be removed in future releases.
Definition at line 621 of file qlowenergycontroller.cpp.
References CentralRole, d, InvalidBluetoothAdapterError, qCWarning, role(), state(), and UnconnectedState.
Referenced by MyClass::btleSharedData(), and MyClass::enableCharNotifications().
|
static |
Returns a new instance of this class with parent.
The remoteDevice must contain the address of the remote Bluetooth Low Energy device to which this object should attempt to connect later on.
The connection is established via localDevice. If localDevice is invalid, the local default device is automatically selected. If localDevice specifies a local device that is not a local Bluetooth adapter, \l error() is set to \l InvalidBluetoothAdapterError once \l connectToDevice() is called.
Note that specifying the local device to be used for the connection is only possible when using BlueZ. All other platforms do not support this feature.
Definition at line 434 of file qlowenergycontroller.cpp.
References QObject::parent().
|
static |
Returns a new object of this class that is in the \l CentralRole and has the parent object parent.
The remoteDevice refers to the device that a connection will be established to later.
The controller uses the local default Bluetooth adapter for the connection management.
Definition at line 412 of file qlowenergycontroller.cpp.
References QObject::parent().
Referenced by MyClass::enableCharNotifications().
|
static |
Returns a new object of this class that is in the \l PeripheralRole and has the parent object parent and is using localDevice.
Typically, the next steps are to add some services and finally call \l startAdvertising() on the returned object.
The peripheral is created on localDevice. If localDevice is invalid, the local default device is automatically selected. If localDevice specifies a local device that is not a local Bluetooth adapter, \l error() is set to \l InvalidBluetoothAdapterError.
Selecting localDevice is only supported on Linux. On other platform, the parameter is ignored.
Definition at line 475 of file qlowenergycontroller.cpp.
References QObject::parent().
|
static |
Returns a new object of this class that is in the \l PeripheralRole and has the parent object parent.
Typically, the next steps are to add some services and finally call \l startAdvertising() on the returned object.
The controller uses the local default Bluetooth adapter for the connection management.
Definition at line 453 of file qlowenergycontroller.cpp.
References QObject::parent().
QLowEnergyService * QLowEnergyController::createServiceObject | ( | const QBluetoothUuid & | serviceUuid, |
QObject * | parent = nullptr |
||
) |
Creates an instance of the service represented by serviceUuid.
The serviceUuid parameter must have been obtained via \l services().
The caller takes ownership of the returned pointer and may pass a parent parameter as default owner.
This function returns a null pointer if no service with serviceUuid can be found on the remote device or the controller is disconnected.
This function can return instances for secondary services too. The include relationships between services can be expressed via \l QLowEnergyService::includedServices().
If this function is called multiple times using the same service UUID, the returned \l QLowEnergyService instances share their internal data. Therefore if one of the instances initiates the discovery of the service details, the other instances automatically transition into the discovery state too.
Definition at line 738 of file qlowenergycontroller.cpp.
References d, it, and QObject::parent().
Referenced by MyClass::btleSharedData(), and MyClass::enableCharNotifications().
|
signal |
This signal is emitted when the controller disconnects from the remote Low Energy device or vice versa.
On iOS and macOS this signal is unreliable if the controller is in the \l PeripheralRole. On Android the signal is emitted when the last connected device is disconnected. On BlueZ DBus backend the controller is considered disconnected when last client which has accessed the attributes has disconnected.
void QLowEnergyController::disconnectFromDevice | ( | ) |
Disconnects from the remote device.
Any \l QLowEnergyService, \l QLowEnergyCharacteristic or \l QLowEnergyDescriptor instance that resulted from the current connection is automatically invalidated. Once any of those objects become invalid they remain invalid even if this controller object reconnects.
This function does nothing if the controller is in the \l UnconnectedState.
If the controller is in the peripheral role, it stops advertising and removes all services which have previously been added via \l addService(). To reuse the QLowEnergyController instance the application must re-add services and restart the advertising mode by calling \l startAdvertising().
Definition at line 659 of file qlowenergycontroller.cpp.
References d, state(), and UnconnectedState.
Referenced by ~QLowEnergyController().
void QLowEnergyController::discoverServices | ( | ) |
Initiates the service discovery process.
The discovery progress is indicated via the \l serviceDiscovered() signal. The \l discoveryFinished() signal is emitted when the process has finished.
If the controller instance is not connected or the controller has performed the service discovery already this function will do nothing.
Definition at line 686 of file qlowenergycontroller.cpp.
References CentralRole, ConnectedState, d, DiscoveringState, and qCWarning.
|
signal |
This signal is emitted when the running service discovery finishes.
The signal is not emitted if the discovery process finishes with an error.
This signal can only be emitted if the controller is in the \l CentralRole.
QLowEnergyController::Error QLowEnergyController::error | ( | ) | const |
Returns the last occurred error or \l NoError.
Definition at line 895 of file qlowenergycontroller.cpp.
References QLowEnergyControllerPrivate::error.
|
signal |
This signal is emitted when an error occurs.
The newError parameter describes the error that occurred.
QString QLowEnergyController::errorString | ( | ) | const |
Returns a textual representation of the last occurred error.
The string is translated.
Definition at line 904 of file qlowenergycontroller.cpp.
References QLowEnergyControllerPrivate::errorString.
QBluetoothAddress QLowEnergyController::localAddress | ( | ) | const |
Returns the address of the local Bluetooth adapter being used for the communication.
If this class instance was requested to use the default adapter but there was no default adapter when creating this class instance, the returned \l QBluetoothAddress will be null.
Definition at line 517 of file qlowenergycontroller.cpp.
References QLowEnergyControllerPrivate::localAdapter.
int QLowEnergyController::mtu | ( | ) | const |
Returns the MTU size.
During connection setup, the ATT MTU size is negotiated. This method provides the result of this negotiation. It can be used to optimize packet sizes in some situations. The maximum amount of data which can be transferred in a single packet is {mtu-3} bytes. 3 bytes are required for the ATT protocol header.
Before the connection setup and MTU negotiation, the default value of 23
will be returned.
Not every platform exposes the MTU value. On those platforms (e.g. Linux) this function always returns -1
.
If the controller is in the \l PeripheralRole, there might be several central devices connected to it. In those cases this function returns the MTU of the last connection that was negotiated.
Definition at line 944 of file qlowenergycontroller.cpp.
References QLowEnergyControllerPrivate::mtu().
|
signal |
This signal is emitted as a result of a successful MTU change.
mtu represents the new value.
void QLowEnergyController::readRssi | ( | ) |
readRssi() reads RSSI (received signal strength indicator) for a connected remote device.
If the read was successful, the RSSI is then reported by rssiRead() signal.
Definition at line 963 of file qlowenergycontroller.cpp.
References CentralRole, ClosingState, ConnectingState, qCWarning, QLowEnergyControllerPrivate::readRssi(), role(), RssiReadError, QLowEnergyControllerPrivate::setError(), state(), and UnconnectedState.
QBluetoothAddress QLowEnergyController::remoteAddress | ( | ) | const |
Returns the address of the remote Bluetooth Low Energy device.
For a controller in the \l CentralRole, this value will always be the one passed in when the controller object was created. For a controller in the \l PeripheralRole, this value is one of the currently connected client device addresses. This address will be invalid if the controller is not currently in the \l ConnectedState.
Definition at line 530 of file qlowenergycontroller.cpp.
References QLowEnergyControllerPrivate::remoteDevice.
QLowEnergyController::RemoteAddressType QLowEnergyController::remoteAddressType | ( | ) | const |
Returns the type of \l remoteAddress().
By default, this value is initialized to \l PublicAddress.
Definition at line 579 of file qlowenergycontroller.cpp.
References QLowEnergyControllerPrivate::addressType.
QBluetoothUuid QLowEnergyController::remoteDeviceUuid | ( | ) | const |
Returns the unique identifier of the remote Bluetooth Low Energy device.
On macOS/iOS/tvOS CoreBluetooth does not expose/accept hardware addresses for LE devices; instead developers are supposed to use unique 128-bit UUIDs, generated by CoreBluetooth. These UUIDS will stay constant for the same central <-> peripheral pair and we use them when connecting to a remote device. For a controller in the \l CentralRole, this value will always be the one passed in when the controller object was created. For a controller in the \l PeripheralRole, this value is invalid.
Definition at line 547 of file qlowenergycontroller.cpp.
References QLowEnergyControllerPrivate::deviceUuid.
QString QLowEnergyController::remoteName | ( | ) | const |
Returns the name of the remote Bluetooth Low Energy device, if the controller is in the \l CentralRole.
Otherwise the result is unspecified.
Definition at line 558 of file qlowenergycontroller.cpp.
References QLowEnergyControllerPrivate::remoteName.
void QLowEnergyController::requestConnectionUpdate | ( | const QLowEnergyConnectionParameters & | parameters | ) |
Requests the controller to update the connection according to parameters.
If the request is successful, the \l connectionUpdated() signal will be emitted with the actual new parameters. See the \l QLowEnergyConnectionParameters class for more information on connection parameters.
Android only indirectly permits the adjustment of this parameter set. The connection parameters are separated into three categories (high, low & balanced priority). Each category implies a pre-configured set of values for \l QLowEnergyConnectionParameters::minimumInterval(), \l QLowEnergyConnectionParameters::maximumInterval() and \l QLowEnergyConnectionParameters::latency(). Although the connection request is an asynchronous operation, Android does not provide a callback stating the result of the request. This is an acknowledged Android bug. Due to this bug Android does not emit the \l connectionUpdated() signal.
Definition at line 879 of file qlowenergycontroller.cpp.
References ConnectedState, DiscoveredState, DiscoveringState, qCWarning, QLowEnergyControllerPrivate::requestConnectionUpdate(), and state().
QLowEnergyController::Role QLowEnergyController::role | ( | ) | const |
Returns the role that this controller object is in.
The role is determined when constructing a QLowEnergyController instance using \l createCentral() or \l createPeripheral().
Definition at line 917 of file qlowenergycontroller.cpp.
References QLowEnergyControllerPrivate::role.
Referenced by addService(), connectToDevice(), readRssi(), and startAdvertising().
This signal is emitted after successful read of RSSI (received signal strength indicator) for a connected remote device.
rssi parameter represents the new value.
|
signal |
This signal is emitted each time a new service is discovered.
The newService parameter contains the UUID of the found service.
This signal can only be emitted if the controller is in the CentralRole
.
QList< QBluetoothUuid > QLowEnergyController::services | ( | ) | const |
Returns the list of services offered by the remote device, if the controller is in the \l CentralRole.
Otherwise, the result is unspecified.
The list contains all primary and secondary services.
Definition at line 709 of file qlowenergycontroller.cpp.
References QLowEnergyControllerPrivate::serviceList.
void QLowEnergyController::setRemoteAddressType | ( | QLowEnergyController::RemoteAddressType | type | ) |
Sets the remote address type.
The type is required to connect to the remote Bluetooth Low Energy device.
This attribute is only required to be set on Linux/BlueZ systems with older Linux kernels (v3.3 or lower), or if CAP_NET_ADMIN is not set for the executable. The default value of the attribute is \l RandomAddress.
Definition at line 601 of file qlowenergycontroller.cpp.
References QLowEnergyControllerPrivate::addressType.
void QLowEnergyController::startAdvertising | ( | const QLowEnergyAdvertisingParameters & | parameters, |
const QLowEnergyAdvertisingData & | advertisingData, | ||
const QLowEnergyAdvertisingData & | scanResponseData = QLowEnergyAdvertisingData() |
||
) |
Starts advertising the data given in advertisingData and scanResponseData, using the parameters set in parameters.
The controller has to be in the \l PeripheralRole. If parameters indicates that the advertisement should be connectable, then this function also starts listening for incoming client connections.
Providing scanResponseData is not required, as it is not applicable for certain configurations of parameters
. advertisingData and scanResponseData are limited to 31 byte user data. If, for example, several 128bit uuids are added to advertisingData, the advertised packets may not contain all uuids. The existing limit may have caused the truncation of uuids. In such cases scanResponseData may be used for additional information.
On BlueZ DBus backend BlueZ decides if, and which data, to use in a scan response. Therefore all advertisement data is recommended to set in the main advertisingData parameter. If both advertisement and scan response data is set, the scan response data is given precedence.
If this object is currently not in the \l UnconnectedState, nothing happens.
Definition at line 776 of file qlowenergycontroller.cpp.
References d, PeripheralRole, qCWarning, role(), state(), and UnconnectedState.
QLowEnergyController::ControllerState QLowEnergyController::state | ( | ) | const |
Returns the current state of the controller.
Definition at line 568 of file qlowenergycontroller.cpp.
References QLowEnergyControllerPrivate::state.
Referenced by addService(), connectToDevice(), disconnectFromDevice(), readRssi(), requestConnectionUpdate(), startAdvertising(), and stopAdvertising().
|
signal |
void QLowEnergyController::stopAdvertising | ( | ) |
Stops advertising, if this object is currently in the advertising state.
The controller has to be in the \l PeripheralRole for this function to work. It does not invalidate services which have previously been added via \l addService().
Definition at line 801 of file qlowenergycontroller.cpp.
References AdvertisingState, d, qCDebug, and state().