QBluetoothServiceDiscoveryAgent

Since: 1.2

#include <QtConnectivity/QBluetoothServiceDiscoveryAgent>

The QBluetoothServiceDiscoveryAgent class provides an API for querying the services provided by a Bluetooth device.

To query the services provided by all contactable Bluetooth devices create an instance of QBluetoothServiceDiscoveryAgent, connect to either the serviceDiscovered() or finished() signals and call start().

    QBluetoothServiceDiscoveryAgent *discoveryAgent = new QBluetoothServiceDiscoveryAgent(this);

    connect(discoveryAgent, SIGNAL(serviceDiscovered(const QBluetoothServiceInfo&)),
            this, SLOT(serviceDiscovered(const QBluetoothServiceInfo&)));

    // Automatically delete agent when service discovery finishes.
    connect(discoveryAgent, SIGNAL(finished()), this, SLOT(deleteLater()));

    discoveryAgent->start();
By default a minimal service discovery is performed. In this mode the QBluetotohServiceInfo objects returned are guaranteed to contain only device and service UUID information. Depending on platform and device capabilities other service information may also be available. For most use cases this is adequate as QBluetoothSocket::connectToService() will perform additional discovery if required. If full service information is required pass FullDiscovery as the discoveryMode parameter to start().

Overview

Public Types Index

Public Functions Index

QBluetoothServiceDiscoveryAgent (QObject *parent=0)
QBluetoothServiceDiscoveryAgent (const QBluetoothAddress &remoteAddress, QObject *parent=0)
~QBluetoothServiceDiscoveryAgent ()
QList< QBluetoothServiceInfo >discoveredServices () const
Errorerror () const
QStringerrorString () const
boolisActive () const
voidsetUuidFilter (const QList< QBluetoothUuid > &uuids)
voidsetUuidFilter (const QBluetoothUuid &uuid)
QList< QBluetoothUuid >uuidFilter () const

Public Slots Index

voidclear ()
voidstart (DiscoveryMode mode=MinimalDiscovery)
voidstop ()

Signals Index

voidcanceled ()
voiderror (QBluetoothServiceDiscoveryAgent::Error error)
voidfinished ()
voidserviceDiscovered (const QBluetoothServiceInfo &info)

Public Types

DiscoveryMode

This enum describes the service discovery mode.

MinimalDiscovery Performs a minimal service discovery. The QBluetoothServiceInfo objects returned may be incomplete and are only guaranteed to contain device and service UUID information. FullDiscovery Performs a full service discovery.

MinimalDiscovery
FullDiscovery

Error

This enum describes errors that can occur during service discovery.

NoError No error. DeviceDiscoveryError Error occurred during device discovery. UnknownError An unidentified error occurred.

NoError
DeviceDiscoveryError
UnknownError 100

Public Functions

QBluetoothServiceDiscoveryAgent (

Constructs a new QBluetoothServiceDiscoveryAgent with parent.

Services will be discovered on all contactable devices.

QBluetoothServiceDiscoveryAgent (

Constructs a new QBluetoothServiceDiscoveryAgent for remoteAddress and with parent.

If remoteAddress is null services will be discovred on all contactable Bluetooth devices.

~QBluetoothServiceDiscoveryAgent ()

Destructor.

QList< QBluetoothServiceInfo > discoveredServices ()

Returns the list of all discovered services.

Error error ()

Returns the type of error that last occurred.

If service discovery is done on a signle address it will returns errors when trying to discover services on that device. If the alternate constructor is used and devices are discovered by a scan, then errors doing service discovery on individual devices are not saved and no signals are emitted. In this case errors are fairly normal since some devices may not respond to discovery or may no longer be in range. As such errors are surpressed. If no services are returned, it can be assumed no services could be discovered.

QString errorString ()

Returns a human-readable description of the last error that occurred when doing service discovery on a single device.

bool isActive ()

Returns true if service discovery is currently active, otherwise returns false.

void setUuidFilter (

Sets the UUID filter to uuids.

See also:

uuidFilter()

void setUuidFilter (

This is an overloaded member function, provided for convenience.

Sets the UUID filter to a list containing the single element uuid.

See also:

uuidFilter()

QList< QBluetoothUuid > uuidFilter ()

Returns the UUID filter.

See also:

setUuidFilter()

Public Slots

void clear ()

Clears the results of a previous service discovery.

void start (

Starts service discovery.

mode specifies the type of service discovery to perform.

See also:

DiscoveryMode

void stop ()

Stops service discovery.

Signals

void canceled ()

Signals the cancellation of the service discovery.

void error (

This signal is emitted when an error occurs.

The error parameter describes the error that occurred.

void finished ()

This signal is emitted when Bluetooth service discovery completes.

void serviceDiscovered (

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

Last modified: 2014-09-30



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus