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
QBluetoothServiceDiscoveryAgent Class Reference

\inmodule QtBluetooth More...

#include <qbluetoothservicediscoveryagent.h>

+ Inheritance diagram for QBluetoothServiceDiscoveryAgent:
+ Collaboration diagram for QBluetoothServiceDiscoveryAgent:

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< QBluetoothServiceInfodiscoveredServices () 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< QBluetoothUuiduuidFilter () 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< QStringbindableObjectName ()
 
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).
 
QThreadthread () 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 >
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 >
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 QObjectListchildren () 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< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () 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
QObjectsender () 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< QObjectDatad_ptr
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Detailed Description

\inmodule QtBluetooth

The QBluetoothServiceDiscoveryAgent class enables you to query for Bluetooth services.

Since
5.2

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.

See also
QBluetoothDeviceDiscoveryAgent, QLowEnergyController

Definition at line 25 of file qbluetoothservicediscoveryagent.h.

Member Enumeration Documentation

◆ DiscoveryMode

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.

◆ Error

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.

Constructor & Destructor Documentation

◆ QBluetoothServiceDiscoveryAgent() [1/2]

QBluetoothServiceDiscoveryAgent::QBluetoothServiceDiscoveryAgent ( QObject * parent = nullptr)
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.

◆ QBluetoothServiceDiscoveryAgent() [2/2]

QBluetoothServiceDiscoveryAgent::QBluetoothServiceDiscoveryAgent ( const QBluetoothAddress & deviceAdapter,
QObject * parent = nullptr )
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.

Note
On WinRT the passed adapter address will be ignored.
On Android passing any deviceAdapter address is meaningless as Android 6.0 or later does not publish the local Bluetooth address anymore. Subsequently, the passed adapter address can never be matched against the local adapter address. Therefore the subsequent call to \l start() will always trigger \l InvalidBluetoothAdapterError.
See also
error()

Definition at line 149 of file qbluetoothservicediscoveryagent.cpp.

References QBluetoothLocalDevice::allDevices(), QBluetoothServiceDiscoveryAgentPrivate::error, QBluetoothServiceDiscoveryAgentPrivate::errorString, InvalidBluetoothAdapterError, and tr.

+ Here is the call graph for this function:

◆ ~QBluetoothServiceDiscoveryAgent()

QBluetoothServiceDiscoveryAgent::~QBluetoothServiceDiscoveryAgent ( )

Destructor for QBluetoothServiceDiscoveryAgent.

Definition at line 170 of file qbluetoothservicediscoveryagent.cpp.

References disconnect(), isActive(), and stop().

+ Here is the call graph for this function:

Member Function Documentation

◆ canceled

QBluetoothServiceDiscoveryAgent::canceled ( )
signal

This signal is triggered when the service discovery was canceled via a call to \l stop().

◆ clear

void QBluetoothServiceDiscoveryAgent::clear ( )
slot

Clears the results of previous service discoveries and resets \l uuidFilter().

This function does nothing during an ongoing service discovery (see \l isActive()).

See also
discoveredServices()

Definition at line 353 of file qbluetoothservicediscoveryagent.cpp.

References d, and isActive().

+ Here is the call graph for this function:

◆ discoveredServices()

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.

Note
The list of services should always be cleared before the discovery mode is changed.
See also
clear()

Definition at line 192 of file qbluetoothservicediscoveryagent.cpp.

References d.

◆ error()

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.

References d.

◆ errorOccurred

void QBluetoothServiceDiscoveryAgent::errorOccurred ( QBluetoothServiceDiscoveryAgent::Error error)
signal

This signal is emitted when an error occurs.

The error parameter describes the error that occurred.

Since
6.2

◆ errorString()

QString QBluetoothServiceDiscoveryAgent::errorString ( ) const

Returns a human-readable description of the last error that occurred during the service discovery.

See also
error(), errorOccurred()

Definition at line 402 of file qbluetoothservicediscoveryagent.cpp.

References d.

◆ finished

QBluetoothServiceDiscoveryAgent::finished ( )
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.

Referenced by QBluetoothSocket::doDeviceDiscovery().

+ Here is the caller graph for this function:

◆ isActive()

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.

References d, and QBluetoothServiceDiscoveryAgentPrivate::Inactive.

Referenced by ~QBluetoothServiceDiscoveryAgent(), clear(), setRemoteAddress(), and stop().

+ Here is the caller graph for this function:

◆ remoteAddress()

QBluetoothAddress QBluetoothServiceDiscoveryAgent::remoteAddress ( ) const

Returns the remote device address.

If \l setRemoteAddress() is not called, the function will return a default constructed \l QBluetoothAddress.

See also
setRemoteAddress()

Definition at line 273 of file qbluetoothservicediscoveryagent.cpp.

References QBluetoothServiceDiscoveryAgentPrivate::deviceAddress.

◆ serviceDiscovered

QBluetoothServiceDiscoveryAgent::serviceDiscovered ( const QBluetoothServiceInfo & info)
signal

This signal is emitted when the Bluetooth service described by info is discovered.

Note
The passed \l QBluetoothServiceInfo parameter may contain a Bluetooth Low Energy service if the target device advertises the service via SDP. This is required from device which support both, classic Bluetooth (BaseRate) and Low Energy services.
See also
QBluetoothDeviceInfo::coreConfigurations()

Referenced by QBluetoothSocket::doDeviceDiscovery().

+ Here is the caller graph for this function:

◆ setRemoteAddress()

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.

See also
remoteAddress()

Definition at line 257 of file qbluetoothservicediscoveryagent.cpp.

References QBluetoothServiceDiscoveryAgentPrivate::deviceAddress, and isActive().

+ Here is the call graph for this function:

◆ setUuidFilter() [1/2]

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.

See also
uuidFilter()

Definition at line 225 of file qbluetoothservicediscoveryagent.cpp.

References d.

◆ setUuidFilter() [2/2]

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.

See also
uuidFilter()

Definition at line 208 of file qbluetoothservicediscoveryagent.cpp.

References d.

◆ start

void QBluetoothServiceDiscoveryAgent::start ( DiscoveryMode mode = MinimalDiscovery)
slot

Starts service discovery.

mode specifies the type of service discovery to perform.

On some platforms, device discovery may lead to pairing requests.

See also
DiscoveryMode

Definition at line 295 of file qbluetoothservicediscoveryagent.cpp.

References d, QBluetoothServiceDiscoveryAgentPrivate::Inactive, InvalidBluetoothAdapterError, NoError, and DarwinBluetooth::qt_test_iobluetooth_runloop().

Referenced by MyClass::startServiceDiscovery().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stop

void QBluetoothServiceDiscoveryAgent::stop ( )
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.

References d, QBluetoothServiceDiscoveryAgentPrivate::DeviceDiscovery, InvalidBluetoothAdapterError, isActive(), and QBluetoothServiceDiscoveryAgentPrivate::ServiceDiscovery.

Referenced by ~QBluetoothServiceDiscoveryAgent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ uuidFilter()

QList< QBluetoothUuid > QBluetoothServiceDiscoveryAgent::uuidFilter ( ) const

Returns the UUID filter.

See also
setUuidFilter()

Definition at line 238 of file qbluetoothservicediscoveryagent.cpp.

References d.


The documentation for this class was generated from the following files: