QBluetoothLocalDevice Class

The QBluetoothLocalDevice class enables access to the local Bluetooth device. More...

Header: #include <QBluetoothLocalDevice>
qmake: QT += bluetooth
Since: Qt 5.2
Inherits: QObject

Public Types

enum Error { NoError, PairingError, UnknownError }
enum HostMode { HostPoweredOff, HostConnectable, HostDiscoverable, HostDiscoverableLimitedInquiry }
enum Pairing { Unpaired, Paired, AuthorizedPaired }

Public Functions

QBluetoothLocalDevice(QObject *parent = nullptr)
QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent = nullptr)
virtual ~QBluetoothLocalDevice()
QBluetoothAddress address() const
QList<QBluetoothAddress> connectedDevices() const
QBluetoothLocalDevice::HostMode hostMode() const
bool isValid() const
QString name() const
QBluetoothLocalDevice::Pairing pairingStatus(const QBluetoothAddress &address) const
void powerOn()
void requestPairing(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing)
void setHostMode(QBluetoothLocalDevice::HostMode mode)
  • 31 public functions inherited from QObject

Public Slots

void pairingConfirmation(bool confirmation)
  • 1 public slot inherited from QObject

Signals

void deviceConnected(const QBluetoothAddress &address)
void deviceDisconnected(const QBluetoothAddress &address)
void error(QBluetoothLocalDevice::Error error)
void hostModeStateChanged(QBluetoothLocalDevice::HostMode state)
void pairingDisplayConfirmation(const QBluetoothAddress &address, QString pin)
void pairingDisplayPinCode(const QBluetoothAddress &address, QString pin)
void pairingFinished(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing)

Static Public Members

QList<QBluetoothHostInfo> allDevices()
const QMetaObject staticMetaObject
  • 9 static public members inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 9 protected functions inherited from QObject

Detailed Description

The QBluetoothLocalDevice class enables access to the local Bluetooth device.

QBluetoothLocalDevice provides functions for getting and setting the state of local Bluetooth devices.

On iOS and Windows, this class cannot be used because the platform does not expose any data or API which may provide information on the local Bluetooth device.

Member Type Documentation

enum QBluetoothLocalDevice::Error

This enum describes errors that maybe returned

ConstantValueDescription
QBluetoothLocalDevice::NoError0No known error
QBluetoothLocalDevice::PairingError1Error in pairing
QBluetoothLocalDevice::UnknownError100Unknown error

enum QBluetoothLocalDevice::HostMode

This enum describes the most of the local Bluetooth device.

ConstantValueDescription
QBluetoothLocalDevice::HostPoweredOff0Power off the device
QBluetoothLocalDevice::HostConnectable1Remote Bluetooth devices can connect to the local Bluetooth device if they have previously been paired with it or otherwise know its address. This powers up the device if it was powered off.
QBluetoothLocalDevice::HostDiscoverable2Remote Bluetooth devices can discover the presence of the local Bluetooth device. The device will also be connectable, and powered on. On Android, this mode can only be active for a maximum of 5 minutes.
QBluetoothLocalDevice::HostDiscoverableLimitedInquiry3Remote Bluetooth devices can discover the presence of the local Bluetooth device when performing a limited inquiry. This should be used for locating services that are only made discoverable for a limited period of time. This can speed up discovery between gaming devices, as service discovery can be skipped on devices not in LimitedInquiry mode. In this mode, the device will be connectable and powered on, if required. This mode is is not supported on Android. On macOS, it is not possible to set the hostMode() to HostConnectable or HostPoweredOff.

enum QBluetoothLocalDevice::Pairing

This enum describes the pairing state between the two Bluetooth devices.

ConstantValueDescription
QBluetoothLocalDevice::Unpaired0The Bluetooth devices are not paired.
QBluetoothLocalDevice::Paired1The Bluetooth devices are paired. The system will prompt the user for authorization when the remote device initiates a connection to the local device.
QBluetoothLocalDevice::AuthorizedPaired2The Bluetooth devices are paired. The system will not prompt the user for authorization when the remote device initiates a connection to the local device.

Member Function Documentation

QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent = nullptr)

Default constructs an instance of QBluetoothLocalDevice.

QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent = nullptr)

Default constructs an instance of QBluetoothLocalDevice.

[virtual] QBluetoothLocalDevice::~QBluetoothLocalDevice()

Destroys the QBluetoothLocalDevice.

QBluetoothAddress QBluetoothLocalDevice::address() const

[static] QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices()

QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const

[signal] void QBluetoothLocalDevice::deviceConnected(const QBluetoothAddress &address)

[signal] void QBluetoothLocalDevice::deviceDisconnected(const QBluetoothAddress &address)

[signal] void QBluetoothLocalDevice::error(QBluetoothLocalDevice::Error error)

QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const

See also setHostMode().

[signal] void QBluetoothLocalDevice::hostModeStateChanged(QBluetoothLocalDevice::HostMode state)

bool QBluetoothLocalDevice::isValid() const

Returns true if the QBluetoothLocalDevice represents an available local Bluetooth device; otherwise return false.

If the local Bluetooth adapter represented by an instance of this class is removed from the system (e.g. removal of the underlying Bluetooth dongle) then this instance will become invalid. An already invalid QBluetoothLocalDevice instance remains invalid even if the same Bluetooth adapter is returned to the system.

See also allDevices().

QString QBluetoothLocalDevice::name() const

[slot] void QBluetoothLocalDevice::pairingConfirmation(bool confirmation)

[signal] void QBluetoothLocalDevice::pairingDisplayConfirmation(const QBluetoothAddress &address, QString pin)

[signal] void QBluetoothLocalDevice::pairingDisplayPinCode(const QBluetoothAddress &address, QString pin)

[signal] void QBluetoothLocalDevice::pairingFinished(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing)

QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const

void QBluetoothLocalDevice::powerOn()

void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing)

void QBluetoothLocalDevice::setHostMode(QBluetoothLocalDevice::HostMode mode)

See also hostMode().