155QBluetoothServiceDiscoveryAgent::QBluetoothServiceDiscoveryAgent(
const QBluetoothAddress &deviceAdapter, QObject *parent)
157 d_ptr(
new QBluetoothServiceDiscoveryAgentPrivate(
this, deviceAdapter))
159 if (!deviceAdapter.isNull()) {
160 const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices();
161 for (
const QBluetoothHostInfo &hostInfo : localDevices) {
162 if (hostInfo.address() == deviceAdapter)
165 d_ptr->error = InvalidBluetoothAdapterError;
166 d_ptr->errorString = tr(
"Invalid Bluetooth adapter address");
301void QBluetoothServiceDiscoveryAgent::start(DiscoveryMode mode)
303 Q_D(QBluetoothServiceDiscoveryAgent);
304#ifdef QT_OSX_BLUETOOTH
306 DarwinBluetooth::qt_test_iobluetooth_runloop();
309 if (d->discoveryState() == QBluetoothServiceDiscoveryAgentPrivate::Inactive
310 && d->error != InvalidBluetoothAdapterError) {
314 d->foundHostAdapterPath.clear();
316 d->setDiscoveryMode(mode);
318 d->error = QBluetoothServiceDiscoveryAgent::NoError;
319 d->errorString.clear();
320 if (d->deviceAddress.isNull()) {
321 d->startDeviceDiscovery();
323 d->discoveredDevices << QBluetoothDeviceInfo(d->deviceAddress, QString(), 0);
324 d->startServiceDiscovery();
333void QBluetoothServiceDiscoveryAgent::stop()
335 Q_D(QBluetoothServiceDiscoveryAgent);
337 if (d->error == InvalidBluetoothAdapterError || !isActive())
340 switch (d->discoveryState()) {
341 case QBluetoothServiceDiscoveryAgentPrivate::DeviceDiscovery:
342 d->stopDeviceDiscovery();
344 case QBluetoothServiceDiscoveryAgentPrivate::ServiceDiscovery:
345 d->stopServiceDiscovery();
351 d->discoveredDevices.clear();
428 Q_Q(QBluetoothServiceDiscoveryAgent);
430 if (!deviceDiscoveryAgent) {
432 deviceDiscoveryAgent =
new QBluetoothDeviceDiscoveryAgent(m_deviceAdapterAddress, q);
434 deviceDiscoveryAgent =
new QBluetoothDeviceDiscoveryAgent(q);
436 QObject::connect(deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished,
438 this->_q_deviceDiscoveryFinished();
440 QObject::connect(deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered,
441 q, [
this](
const QBluetoothDeviceInfo &info){
442 this->_q_deviceDiscovered(info);
444 QObject::connect(deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::errorOccurred, q,
445 [
this](QBluetoothDeviceDiscoveryAgent::Error newError) {
446 this->_q_deviceDiscoveryError(newError);
450 setDiscoveryState(DeviceDiscovery);
452 deviceDiscoveryAgent->start(QBluetoothDeviceDiscoveryAgent::ClassicMethod);
479 if (deviceDiscoveryAgent->error() != QBluetoothDeviceDiscoveryAgent::NoError) {
481 error =
static_cast<QBluetoothServiceDiscoveryAgent::Error>(deviceDiscoveryAgent->error());
482 errorString = deviceDiscoveryAgent->errorString();
483 setDiscoveryState(Inactive);
484 Q_Q(QBluetoothServiceDiscoveryAgent);
485 emit q->errorOccurred(error);
490 delete deviceDiscoveryAgent;
491 deviceDiscoveryAgent =
nullptr;
508 error =
static_cast<QBluetoothServiceDiscoveryAgent::Error>(newError);
509 errorString = deviceDiscoveryAgent->errorString();
513 deviceDiscoveryAgent->disconnect();
515 deviceDiscoveryAgent->stop();
516 delete deviceDiscoveryAgent;
517 deviceDiscoveryAgent =
nullptr;
519 setDiscoveryState(Inactive);
520 Q_Q(QBluetoothServiceDiscoveryAgent);
521 emit q->errorOccurred(error);