QBluetoothDeviceDiscoveryAgent Class

The QBluetoothDeviceDiscoveryAgent class discovers the Bluetooth devices nearby. More...

Header: #include <QBluetoothDeviceDiscoveryAgent>
qmake: QT += bluetooth
Inherits: QObject.

Public Types

enum Error { NoError, PoweredOffError, InputOutputError, UnknownError }
enum InquiryType { GeneralUnlimitedInquiry, LimitedInquiry }

Properties

  • inquiryType : QBluetoothDeviceDiscoveryAgent::InquiryType
  • 1 property inherited from QObject

Public Functions

QBluetoothDeviceDiscoveryAgent(QObject * parent = 0)
QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress & deviceAdapter, QObject * parent = 0)
~QBluetoothDeviceDiscoveryAgent()
QList<QBluetoothDeviceInfo> discoveredDevices() const
Error error() const
QString errorString() const
QBluetoothDeviceDiscoveryAgent::InquiryType inquiryType() const
bool isActive() const
void setInquiryType(QBluetoothDeviceDiscoveryAgent::InquiryType type)
  • 31 public functions inherited from QObject

Public Slots

void start()
void stop()
  • 1 public slot inherited from QObject

Signals

void canceled()
void deviceDiscovered(const QBluetoothDeviceInfo & info)
void error(QBluetoothDeviceDiscoveryAgent::Error error)
void finished()

Additional Inherited Members

  • 1 public variable inherited from QObject
  • 10 static public members inherited from QObject
  • 9 protected functions inherited from QObject
  • 2 protected variables inherited from QObject

Detailed Description

The QBluetoothDeviceDiscoveryAgent class discovers the Bluetooth devices nearby.

To discover the nearby Bluetooth devices:

// Create a discovery agent and connect to its signals
QBluetoothDiscoveryAgent *discoveryAgent = new QBluetoothDiscoveryAgent(this);
connect(discoveryAgent, SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo&)),
        this, SLOT(deviceDiscovered(const QBluetoothDeviceInfo&)));

// Start a discovery
discoveryAgent->start();

...

// In your local slot, read information about the found devices
void MyClass::deviceDiscovered(const QBluetoothDeviceInfo &device)
{
    qDebug() << "Found new device:" << device.name() << '(' << device.address().toString() << ')';
}

To retrieve results asynchronously, connect to the deviceDiscovered() signal. To get a list of all discovered devices, call discoveredDevices() after the finished() signal.

Member Type Documentation

enum QBluetoothDeviceDiscoveryAgent::Error

Indicates all possible error conditions found during Bluetooth device discovery.

ConstantValueDescription
QBluetoothDeviceDiscoveryAgent::NoError0No error has occurred.
QBluetoothDeviceDiscoveryAgent::PoweredOffError2The Bluetooth adaptor is powered off, power it on before doing discovery.
QBluetoothDeviceDiscoveryAgent::InputOutputError1Writing or reading from the device resulted in an error.
QBluetoothDeviceDiscoveryAgent::UnknownError100An unknown error has occurred.

enum QBluetoothDeviceDiscoveryAgent::InquiryType

This enum describes the inquiry type used while discovering Bluetooth devices.

ConstantValueDescription
QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry0A general unlimited inquiry. Discovers all visible Bluetooth devices in the local vicinity.
QBluetoothDeviceDiscoveryAgent::LimitedInquiry1A limited inquiry discovers devices that are in limited inquiry mode.

LimitedInquiry is not supported on all platforms. If it is requested on a platform that does not support it, GeneralUnlimitedInquiry will be used instead. Setting LimitedInquiry is useful for multi-player Bluetooth-based games that needs faster communication between the devices. The phone scans for devices in LimitedInquiry and Service Discovery is done on one or two devices to speed up the service scan. After the game has connected to the device it intends to,the device returns to GeneralUnilimitedInquiry.

Property Documentation

inquiryType : QBluetoothDeviceDiscoveryAgent::InquiryType

This property holds type of inquiry scan to be used while discovering devices.

This property affects the type of inquiry scan which is performed while discovering devices.

By default, this property is set to GeneralUnlimitedInquiry.

Not all platforms support LimitedInquiry.

Access functions:

QBluetoothDeviceDiscoveryAgent::InquiryType inquiryType() const
void setInquiryType(QBluetoothDeviceDiscoveryAgent::InquiryType type)

See also InquiryType.

Member Function Documentation

QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(QObject * parent = 0)

Constructs a new Bluetooth device discovery agent with parent parent.

QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress & deviceAdapter, QObject * parent = 0)

Constructs a new Bluetooth device discovery agent with parent parent and uses the adapter deviceAdapter for the device search. If deviceAdapter is default constructed the resulting QBluetoothDeviceDiscoveryAgent object will use the local default Bluetooth adapter.

QBluetoothDeviceDiscoveryAgent::~QBluetoothDeviceDiscoveryAgent()

Destructor for ~QBluetoothDeviceDiscoveryAgent()

void QBluetoothDeviceDiscoveryAgent::canceled() [signal]

This signal is emitted when device discovery is aborted by a call to stop().

void QBluetoothDeviceDiscoveryAgent::deviceDiscovered(const QBluetoothDeviceInfo & info) [signal]

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

QList<QBluetoothDeviceInfo> QBluetoothDeviceDiscoveryAgent::discoveredDevices() const

Returns a list of all discovered Bluetooth devices.

Error QBluetoothDeviceDiscoveryAgent::error() const

Returns the last error.

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

This signal is emitted when an error occurs during Bluetooth device discovery.

See also error() and errorString().

QString QBluetoothDeviceDiscoveryAgent::errorString() const

Returns a human-readable description of the last error.

void QBluetoothDeviceDiscoveryAgent::finished() [signal]

This signal is emitted when Bluetooth device discovery completes.

bool QBluetoothDeviceDiscoveryAgent::isActive() const

Returns true if the agent is currently discovering Bluetooth devices, otherwise returns false.

void QBluetoothDeviceDiscoveryAgent::start() [slot]

Starts Bluetooth device discovery, if it is not already started.

The deviceDiscovered() signal is emitted as each device is discovered. The finished() signal is emitted once device discovery is complete.

void QBluetoothDeviceDiscoveryAgent::stop() [slot]

Stops Bluetooth device discovery. The cancel() signal is emitted once the device discovery is canceled. start() maybe called before the cancel signal is received. Once start() has been called the cancel signal from the prior discovery will be discarded.