Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtBluetooth More...
#include <qbluetoothservicediscoveryagent.h>
Public Types | |
enum | Error { NoError = QBluetoothDeviceDiscoveryAgent::NoError , InputOutputError = QBluetoothDeviceDiscoveryAgent::InputOutputError , PoweredOffError = QBluetoothDeviceDiscoveryAgent::PoweredOffError , InvalidBluetoothAdapterError = QBluetoothDeviceDiscoveryAgent::InvalidBluetoothAdapterError , MissingPermissionsError = QBluetoothDeviceDiscoveryAgent::MissingPermissionsError , UnknownError = QBluetoothDeviceDiscoveryAgent::UnknownError } |
This enum describes errors that can occur during service discovery. More... | |
enum | DiscoveryMode { MinimalDiscovery , FullDiscovery } |
This enum describes the service discovery mode. More... | |
Public Slots | |
void | start (DiscoveryMode mode=MinimalDiscovery) |
Starts service discovery. | |
void | stop () |
Stops the service discovery process. | |
void | clear () |
Clears the results of previous service discoveries and resets \l uuidFilter(). | |
Public Slots inherited from QObject | |
void | deleteLater () |
\threadsafe | |
Signals | |
void | serviceDiscovered (const QBluetoothServiceInfo &info) |
This signal is emitted when the Bluetooth service described by info is discovered. | |
void | finished () |
This signal is emitted when the Bluetooth service discovery completes. | |
void | canceled () |
This signal is triggered when the service discovery was canceled via a call to \l stop(). | |
void | errorOccurred (QBluetoothServiceDiscoveryAgent::Error error) |
This signal is emitted when an error occurs. | |
Signals inherited from QObject | |
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 | |
QBluetoothServiceDiscoveryAgent (QObject *parent=nullptr) | |
Constructs a new QBluetoothServiceDiscoveryAgent with parent. | |
QBluetoothServiceDiscoveryAgent (const QBluetoothAddress &deviceAdapter, QObject *parent=nullptr) | |
Constructs a new QBluetoothServiceDiscoveryAgent for deviceAdapter and with parent. | |
~QBluetoothServiceDiscoveryAgent () | |
Destructor for QBluetoothServiceDiscoveryAgent. | |
bool | isActive () const |
Returns true if the service discovery is currently active; otherwise returns false . | |
Error | error () const |
Returns the type of error that last occurred. | |
QString | errorString () const |
Returns a human-readable description of the last error that occurred during the service discovery. | |
QList< QBluetoothServiceInfo > | discoveredServices () const |
Returns the list of all discovered services. | |
void | setUuidFilter (const QList< QBluetoothUuid > &uuids) |
Sets the UUID filter to uuids. | |
void | setUuidFilter (const QBluetoothUuid &uuid) |
This is an overloaded member function, provided for convenience. | |
QList< QBluetoothUuid > | uuidFilter () const |
Returns the UUID filter. | |
bool | setRemoteAddress (const QBluetoothAddress &address) |
Sets the remote device address to address. | |
QBluetoothAddress | remoteAddress () const |
Returns the remote device address. | |
Public Member Functions inherited from QObject | |
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. | |
bool | moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL) |
Changes the thread affinity for this object and its children and returns true on success. | |
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::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
void | killTimer (Qt::TimerId id) |
template<typename T > | |
T | findChild (QAnyStringView aName, 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 (QAnyStringView 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 > | |
T | findChild (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. | |
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 . | |
Additional Inherited Members | |
Static Public Member Functions inherited from QObject | |
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) |
Protected Member Functions inherited from QObject | |
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) | |
Protected Attributes inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Properties inherited from QObject | |
QString | objectName |
the name of this object | |
Related Symbols inherited from QObject | |
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 QBluetoothServiceDiscoveryAgent class enables you to query for Bluetooth services.
The discovery process relies on the Bluetooth Service Discovery Process (SDP). The following steps are required to query the services provided by all contactable Bluetooth devices:
\list
By default a minimal service discovery is performed. In this mode, the returned \l QBluetoothServiceInfo objects are guaranteed to contain only device and service UUID information. Depending on platform and device capabilities, other service information may also be available. The minimal service discovery mode relies on cached SDP data of the platform. Therefore it is possible that this discovery does not find a device although it is physically available. In such cases a full discovery must be performed to force an update of the platform cache. However for most use cases a minimal discovery is adequate as it is much quicker and other classes which require up-to-date information such as QBluetoothSocket::connectToService() will perform additional discovery if required. If the full service information is required, pass \l FullDiscovery as the discoveryMode parameter to start().
This class may internally utilize \l QBluetoothDeviceDiscoveryAgent to find unknown devices.
The service discovery may find Bluetooth Low Energy services too if the target device is a combination of a classic and Low Energy device. Those devices are required to advertise their Low Energy services via SDP. If the target device only supports Bluetooth Low Energy services, it is likely to not advertise them via SDP. The \l QLowEnergyController class should be utilized to perform the service discovery on Low Energy devices.
On iOS, this class cannot be used because the platform does not expose an API which may permit access to QBluetoothServiceDiscoveryAgent related features.
Definition at line 25 of file qbluetoothservicediscoveryagent.h.
This enum describes the service discovery mode.
\value MinimalDiscovery Performs a minimal service discovery. The QBluetoothServiceInfo objects returned may be incomplete and are only guaranteed to contain device and service UUID information. Since a minimal discovery relies on cached SDP data it may not find a physically existing device until a FullDiscovery
is performed. \value FullDiscovery Performs a full service discovery.
Enumerator | |
---|---|
MinimalDiscovery | |
FullDiscovery |
Definition at line 43 of file qbluetoothservicediscoveryagent.h.
This enum describes errors that can occur during service discovery.
\value NoError No error has occurred. \value PoweredOffError The Bluetooth adaptor is powered off, power it on before doing discovery. \value InputOutputError Writing or reading from the device resulted in an error. \value [since 5.3] InvalidBluetoothAdapterError The passed local adapter address does not match the physical adapter address of any local Bluetooth device. \value [since 6.4] MissingPermissionsError The operating system requests permissions which were not granted by the user. \value UnknownError An unknown error has occurred.
Enumerator | |
---|---|
NoError | |
InputOutputError | |
PoweredOffError | |
InvalidBluetoothAdapterError | |
MissingPermissionsError | |
UnknownError |
Definition at line 31 of file qbluetoothservicediscoveryagent.h.
|
explicit |
Constructs a new QBluetoothServiceDiscoveryAgent with parent.
The search is performed via the local default Bluetooth adapter.
Definition at line 124 of file qbluetoothservicediscoveryagent.cpp.
|
explicit |
Constructs a new QBluetoothServiceDiscoveryAgent for deviceAdapter and with parent.
It uses deviceAdapter for the service search. If deviceAdapter is default constructed the resulting QBluetoothServiceDiscoveryAgent object will use the local default Bluetooth adapter.
If a deviceAdapter is specified that is not a local adapter \l error() will be set to \l InvalidBluetoothAdapterError. Therefore it is recommended to test the error flag immediately after using this constructor.
Definition at line 149 of file qbluetoothservicediscoveryagent.cpp.
QBluetoothServiceDiscoveryAgent::~QBluetoothServiceDiscoveryAgent | ( | ) |
Destructor for QBluetoothServiceDiscoveryAgent.
Definition at line 170 of file qbluetoothservicediscoveryagent.cpp.
|
signal |
This signal is triggered when the service discovery was canceled via a call to \l stop().
|
slot |
Clears the results of previous service discoveries and resets \l uuidFilter().
This function does nothing during an ongoing service discovery (see \l isActive()).
Definition at line 353 of file qbluetoothservicediscoveryagent.cpp.
QList< QBluetoothServiceInfo > QBluetoothServiceDiscoveryAgent::discoveredServices | ( | ) | const |
Returns the list of all discovered services.
This list of services accumulates newly discovered services from multiple calls to \l start(). Unless \l clear() is called the list cannot decrease in size. This implies that if a remote Bluetooth device moves out of range in between two subsequent calls to \l start() the list may contain stale entries.
Definition at line 192 of file qbluetoothservicediscoveryagent.cpp.
QBluetoothServiceDiscoveryAgent::Error QBluetoothServiceDiscoveryAgent::error | ( | ) | const |
Returns the type of error that last occurred.
If the service discovery is done for a single \l remoteAddress() it will return errors that occurred while trying to discover services on that device. If the \l remoteAddress() is not set and devices are discovered by a scan, errors during service discovery on individual devices are not saved and no signals are emitted. In this case, errors are fairly normal as some devices may not respond to discovery or may no longer be in range. Such errors are suppressed. If no services are returned, it can be assumed no services could be discovered.
Any possible previous errors are cleared upon restarting the discovery.
Definition at line 389 of file qbluetoothservicediscoveryagent.cpp.
|
signal |
This signal is emitted when an error occurs.
The error parameter describes the error that occurred.
QString QBluetoothServiceDiscoveryAgent::errorString | ( | ) | const |
Returns a human-readable description of the last error that occurred during the service discovery.
Definition at line 402 of file qbluetoothservicediscoveryagent.cpp.
|
signal |
This signal is emitted when the Bluetooth service discovery completes.
Unlike the \l QBluetoothDeviceDiscoveryAgent::finished() signal this signal will even be emitted when an error occurred during the service discovery. Therefore it is recommended to check the \l errorOccurred() signal to evaluate the success of the service discovery discovery.
bool QBluetoothServiceDiscoveryAgent::isActive | ( | ) | const |
Returns true
if the service discovery is currently active; otherwise returns false
.
An active discovery can be stopped by calling \l stop().
Definition at line 370 of file qbluetoothservicediscoveryagent.cpp.
QBluetoothAddress QBluetoothServiceDiscoveryAgent::remoteAddress | ( | ) | const |
Returns the remote device address.
If \l setRemoteAddress() is not called, the function will return a default constructed \l QBluetoothAddress.
Definition at line 273 of file qbluetoothservicediscoveryagent.cpp.
|
signal |
This signal is emitted when the Bluetooth service described by info is discovered.
bool QBluetoothServiceDiscoveryAgent::setRemoteAddress | ( | const QBluetoothAddress & | address | ) |
Sets the remote device address to address.
If address is default constructed, services will be discovered on all contactable Bluetooth devices. A new remote address can only be set while there is no service discovery in progress; otherwise this function returns false.
On some platforms the service discovery might lead to pairing requests. Therefore it is not recommended to do service discoveries on all devices. This function can be used to restrict the service discovery to a particular device.
Definition at line 257 of file qbluetoothservicediscoveryagent.cpp.
void QBluetoothServiceDiscoveryAgent::setUuidFilter | ( | const QBluetoothUuid & | uuid | ) |
This is an overloaded member function, provided for convenience.
Sets the UUID filter to a list containing the single element uuid. The matching applies to the service's \l {QBluetoothServiceInfo::ServiceId}{ServiceId} and \l {QBluetoothServiceInfo::ServiceClassIds} {ServiceClassIds} attributes.
Definition at line 225 of file qbluetoothservicediscoveryagent.cpp.
void QBluetoothServiceDiscoveryAgent::setUuidFilter | ( | const QList< QBluetoothUuid > & | uuids | ) |
Sets the UUID filter to uuids.
Only services matching the UUIDs in uuids will be returned. The matching applies to the service's \l {QBluetoothServiceInfo::ServiceId}{ServiceId} and \l {QBluetoothServiceInfo::ServiceClassIds} {ServiceClassIds} attributes.
An empty UUID list is equivalent to a list containing only QBluetoothUuid::ServiceClassUuid::PublicBrowseGroup.
Definition at line 208 of file qbluetoothservicediscoveryagent.cpp.
|
slot |
Starts service discovery.
mode specifies the type of service discovery to perform.
On some platforms, device discovery may lead to pairing requests.
Definition at line 295 of file qbluetoothservicediscoveryagent.cpp.
|
slot |
Stops the service discovery process.
The \l canceled() signal will be emitted once the search has stopped.
Definition at line 327 of file qbluetoothservicediscoveryagent.cpp.
QList< QBluetoothUuid > QBluetoothServiceDiscoveryAgent::uuidFilter | ( | ) | const |
Returns the UUID filter.
Definition at line 238 of file qbluetoothservicediscoveryagent.cpp.