QBluetoothServiceInfo Class

The QBluetoothServiceInfo class enables access to the attributes of a Bluetooth service. More...

Header: #include <QBluetoothServiceInfo>
qmake: QT += bluetooth

Public Types

class Alternative
class Sequence
enum AttributeId { ServiceRecordHandle, ServiceClassIds, ServiceRecordState, ServiceId, ProtocolDescriptorList, …, ServiceProvider }
enum Protocol { UnknownProtocol, L2capProtocol, RfcommProtocol }

Public Functions

QBluetoothServiceInfo()
QBluetoothServiceInfo(const QBluetoothServiceInfo &other)
~QBluetoothServiceInfo()
QVariant attribute(quint16 attributeId) const
QList<quint16> attributes() const
bool contains(quint16 attributeId) const
QBluetoothDeviceInfo device() const
bool isComplete() const
bool isRegistered() const
bool isValid() const
QBluetoothServiceInfo::Sequence protocolDescriptor(QBluetoothUuid::ProtocolUuid protocol) const
int protocolServiceMultiplexer() const
bool registerService(const QBluetoothAddress &localAdapter = QBluetoothAddress())
void removeAttribute(quint16 attributeId)
int serverChannel() const
quint8 serviceAvailability() const
QList<QBluetoothUuid> serviceClassUuids() const
QString serviceDescription() const
QString serviceName() const
QString serviceProvider() const
QBluetoothUuid serviceUuid() const
void setAttribute(quint16 attributeId, const QBluetoothServiceInfo::Alternative &value)
void setAttribute(quint16 attributeId, const QBluetoothServiceInfo::Sequence &value)
void setAttribute(quint16 attributeId, const QBluetoothUuid &value)
void setAttribute(quint16 attributeId, const QVariant &value)
void setDevice(const QBluetoothDeviceInfo &device)
void setServiceAvailability(quint8 availability)
void setServiceDescription(const QString &description)
void setServiceName(const QString &name)
void setServiceProvider(const QString &provider)
void setServiceUuid(const QBluetoothUuid &uuid)
QBluetoothServiceInfo::Protocol socketProtocol() const
bool unregisterService()
QBluetoothServiceInfo &operator=(const QBluetoothServiceInfo &other)

Detailed Description

QBluetoothServiceInfo provides information about a service offered by a Bluetooth device. In addition it can be used to register new services on the local device. Note that such a registration only affects the Bluetooth SDP entries. Any server listening for incoming connections (e.g an RFCOMM server) must be started before registerService() is called. Deregistration must happen in the reverse order.

QBluetoothServiceInfo is not a value type in the traditional sense. All copies of the same service info object share the same data as they do not detach upon changing them. This ensures that two copies can (de)register the same Bluetooth service.

On iOS, this class cannot be used because the platform does not expose an API which may permit access to QBluetoothServiceInfo related features.

Member Type Documentation

enum QBluetoothServiceInfo::AttributeId

Bluetooth service attributes. Please check the Bluetooth Core Specification for a more detailed description of these attributes.

ConstantValueDescription
QBluetoothServiceInfo::ServiceRecordHandle0x0000Specifies a service record from which attributes can be retrieved.
QBluetoothServiceInfo::ServiceClassIds0x0001UUIDs of service classes that the service conforms to. The most common service classes are defined in (QBluetoothUuid::ServiceClassUuid)
QBluetoothServiceInfo::ServiceRecordState0x0002Attibute changes when any other service attribute is added, deleted or modified.
QBluetoothServiceInfo::ServiceId0x0003UUID that uniquely identifies the service.
QBluetoothServiceInfo::ProtocolDescriptorList0x0004List of protocols used by the service. The most common protocol Uuids are defined in QBluetoothUuid::ProtocolUuid
QBluetoothServiceInfo::BrowseGroupList0x0005List of browse groups the service is in.
QBluetoothServiceInfo::LanguageBaseAttributeIdList0x0006List of language base attribute IDs to support human-readable attributes.
QBluetoothServiceInfo::ServiceInfoTimeToLive0x0007Number of seconds for which the service record is expected to remain valid and unchanged.
QBluetoothServiceInfo::ServiceAvailability0x0008Value indicating the availability of the service.
QBluetoothServiceInfo::BluetoothProfileDescriptorList0x0009List of profiles to which the service conforms.
QBluetoothServiceInfo::DocumentationUrl0x000AURL that points to the documentation on the service..
QBluetoothServiceInfo::ClientExecutableUrl0x000BURL that refers to the location of an application that can be used to utilize the service.
QBluetoothServiceInfo::IconUrl0x000CURL to the location of the icon representing the service.
QBluetoothServiceInfo::AdditionalProtocolDescriptorList0x000DAdditional protocols used by the service. This attribute extends ProtocolDescriptorList.
QBluetoothServiceInfo::PrimaryLanguageBase0x0100Base index for primary language text descriptors.
QBluetoothServiceInfo::ServiceNamePrimaryLanguageBase + 0x0000Name of the Bluetooth service in the primary language.
QBluetoothServiceInfo::ServiceDescriptionPrimaryLanguageBase + 0x0001Description of the Bluetooth service in the primary language.
QBluetoothServiceInfo::ServiceProviderPrimaryLanguageBase + 0x0002Name of the company / entity that provides the Bluetooth service primary language.

Note: On Windows ServiceClassIds and ProtocolDescriptorList are automatically set to default values when a service is created. Manually setting values for these attributes will not work and might lead to unexpected results on this platform.

enum QBluetoothServiceInfo::Protocol

This enum describes the socket protocol used by the service.

ConstantValueDescription
QBluetoothServiceInfo::UnknownProtocol0The service uses an unknown socket protocol.
QBluetoothServiceInfo::L2capProtocol1The service uses the L2CAP socket protocol. This protocol is not supported for direct socket connections on Android.
QBluetoothServiceInfo::RfcommProtocol2The service uses the RFCOMM socket protocol.

Member Function Documentation

QBluetoothServiceInfo::QBluetoothServiceInfo()

Construct a new invalid QBluetoothServiceInfo;

QBluetoothServiceInfo::QBluetoothServiceInfo(const QBluetoothServiceInfo &other)

Construct a new QBluetoothServiceInfo that is a copy of other.

The two copies continue to share the same underlying data which does not detach upon write.

[noexcept] QBluetoothServiceInfo::~QBluetoothServiceInfo()

Destroys the QBluetoothServiceInfo object.

QVariant QBluetoothServiceInfo::attribute(quint16 attributeId) const

Returns the value of the attribute attributeId.

See also setAttribute().

QList<quint16> QBluetoothServiceInfo::attributes() const

Returns a list of all attribute ids that the QBluetoothServiceInfo object has.

bool QBluetoothServiceInfo::contains(quint16 attributeId) const

Returns true if the QBluetoothServiceInfo object contains the attribute attributeId, otherwise returns false.

QBluetoothDeviceInfo QBluetoothServiceInfo::device() const

Returns the address of the Bluetooth device that provides this service.

See also setDevice().

bool QBluetoothServiceInfo::isComplete() const

Returns true if the QBluetoothServiceInfo object is considered complete, otherwise returns false.

A complete QBluetoothServiceInfo object contains a ProtocolDescriptorList attribute.

bool QBluetoothServiceInfo::isRegistered() const

Returns true if the service information is registered with the platform's Service Discovery Protocol (SDP) implementation, otherwise returns false.

bool QBluetoothServiceInfo::isValid() const

Returns true if the QBluetoothServiceInfo object is valid, otherwise returns false.

An invalid QBluetoothServiceInfo object will have no attributes.

QBluetoothServiceInfo::Sequence QBluetoothServiceInfo::protocolDescriptor(QBluetoothUuid::ProtocolUuid protocol) const

Returns the protocol parameters as a QBluetoothServiceInfo::Sequence for protocol protocol.

An empty QBluetoothServiceInfo::Sequence is returned if protocol is not supported.

int QBluetoothServiceInfo::protocolServiceMultiplexer() const

This is a convenience function. Returns the protocol/service multiplexer for services which support the L2CAP protocol, otherwise returns -1.

This function is equivalent to extracting the information from QBluetoothServiceInfo::Sequence returned by QBluetoothServiceInfo::attribute(QBluetoothServiceInfo::ProtocolDescriptorList).

bool QBluetoothServiceInfo::registerService(const QBluetoothAddress &localAdapter = QBluetoothAddress())

Registers this service with the platform's Service Discovery Protocol (SDP) implementation, making it findable by other devices when they perform service discovery. Returns true if the service is successfully registered, otherwise returns false. Once registered changes to the record cannot be made. The service must be unregistered and registered again with the changes.

The localAdapter parameter determines the local Bluetooth adapter under which the service should be registered. If localAdapter is null the default Bluetooth adapter will be used. If this service info object is already registered via a local adapter and this is function is called using a different local adapter, the previous registration is removed and the service reregistered using the new adapter.

void QBluetoothServiceInfo::removeAttribute(quint16 attributeId)

Removes the attribute attributeId from the QBluetoothServiceInfo object.

If the service information is already registered with the platforms SDP database, the database entry will not be updated until registerService() was called again.

int QBluetoothServiceInfo::serverChannel() const

This is a convenience function. Returns the server channel for services which support the RFCOMM protocol, otherwise returns -1.

This function is equivalent to extracting the information from QBluetoothServiceInfo::Sequence returned by QBluetoothServiceInfo::attribute(QBluetootherServiceInfo::ProtocolDescriptorList).

quint8 QBluetoothServiceInfo::serviceAvailability() const

This is a convenience function. It is equivalent to calling attribute(QBluetoothServiceInfo::ServiceAvailability).toUInt().

Returns the availability of the service.

See also setServiceAvailability() and attribute().

QList<QBluetoothUuid> QBluetoothServiceInfo::serviceClassUuids() const

Returns a list of UUIDs describing the service classes that this service conforms to.

This is a convenience function. It is equivalent to calling attribute(QBluetoothServiceInfo::ServiceClassIds).value<QBluetoothServiceInfo::Sequence>() and subsequently iterating over its QBluetoothUuid entries.

See also attribute().

QString QBluetoothServiceInfo::serviceDescription() const

This is a convenience function. It is equivalent to calling attribute(QBluetoothServiceInfo::ServiceDescription).toString().

Returns the service description in the primary language.

See also setServiceDescription() and attribute().

QString QBluetoothServiceInfo::serviceName() const

This is a convenience function. It is equivalent to calling attribute(QBluetoothServiceInfo::ServiceName).toString().

Returns the service name in the primary language.

See also setServiceName() and attribute().

QString QBluetoothServiceInfo::serviceProvider() const

This is a convenience function. It is equivalent to calling attribute(QBluetoothServiceInfo::ServiceProvider).toString().

Returns the service provider in the primary language.

See also setServiceProvider() and attribute().

QBluetoothUuid QBluetoothServiceInfo::serviceUuid() const

This is a convenience function. It is equivalent to calling attribute(QBluetoothServiceInfo::ServiceId).value<QBluetoothUuid>().

Returns the custom UUID of the service. This UUID may be null. UUIDs based on Bluetooth SIG standards should be retrieved via serviceClassUuids().

See also setServiceUuid() and attribute().

void QBluetoothServiceInfo::setAttribute(quint16 attributeId, const QBluetoothServiceInfo::Alternative &value)

This is a convenience function.

Sets the attribute identified by attributeId to value.

If the service information is already registered with the platform's SDP database, the database entry will not be updated until registerService() was called again.

See also attribute().

void QBluetoothServiceInfo::setAttribute(quint16 attributeId, const QBluetoothServiceInfo::Sequence &value)

This is a convenience function.

Sets the attribute identified by attributeId to value.

If the service information is already registered with the platform's SDP database, the database entry will not be updated until registerService() was called again.

void QBluetoothServiceInfo::setAttribute(quint16 attributeId, const QBluetoothUuid &value)

This is a convenience function.

Sets the attribute identified by attributeId to value.

If the service information is already registered with the platform's SDP database, the database entry will not be updated until registerService() was called again.

void QBluetoothServiceInfo::setAttribute(quint16 attributeId, const QVariant &value)

Sets the attribute identified by attributeId to value.

If the service information is already registered with the platform's SDP database, the database entry will not be updated until registerService() was called again.

Note: If an attribute expectes a byte-encoded value (e.g. Bluetooth HID services), it should be set as QByteArray.

See also isRegistered() and registerService().

void QBluetoothServiceInfo::setDevice(const QBluetoothDeviceInfo &device)

Sets the Bluetooth device that provides this service to device.

See also device().

void QBluetoothServiceInfo::setServiceAvailability(quint8 availability)

This is a convenience function. It is equivalent to calling setAttribute(QBluetoothServiceInfo::ServiceAvailability, availability).

Sets the availabiltiy of the service to availability.

See also serviceAvailability() and setAttribute().

void QBluetoothServiceInfo::setServiceDescription(const QString &description)

This is a convenience function. It is equivalent to calling setAttribute(QBluetoothServiceInfo::ServiceDescription, description).

Sets the service description in the primary language to description.

See also serviceDescription() and setAttribute().

void QBluetoothServiceInfo::setServiceName(const QString &name)

This is a convenience function. It is equivalent to calling setAttribute(QBluetoothServiceInfo::ServiceName, name).

Sets the service name in the primary language to name.

See also serviceName() and setAttribute().

void QBluetoothServiceInfo::setServiceProvider(const QString &provider)

This is a convenience function. It is equivalent to calling setAttribute(QBluetoothServiceInfo::ServiceProvider, provider).

Sets the service provider in the primary language to provider.

See also serviceProvider() and setAttribute().

void QBluetoothServiceInfo::setServiceUuid(const QBluetoothUuid &uuid)

This is a convenience function. It is equivalent to calling setAttribute(QBluetoothServiceInfo::ServiceId, uuid).

Sets the custom service UUID to uuid. This function should not be used to set a standardized service UUID.

See also serviceUuid() and setAttribute().

QBluetoothServiceInfo::Protocol QBluetoothServiceInfo::socketProtocol() const

Returns the protocol that the QBluetoothServiceInfo object uses.

bool QBluetoothServiceInfo::unregisterService()

Unregisters this service with the platform's Service Discovery Protocol (SDP) implementation. After this, the service will no longer be findable by other devices through service discovery.

Returns true if the service is successfully unregistered, otherwise returns false.

QBluetoothServiceInfo &QBluetoothServiceInfo::operator=(const QBluetoothServiceInfo &other)

Makes a copy of the other and assigns it to this QBluetoothServiceInfo object. The two copies continue to share the same service and registration details.