149QBluetoothServiceDiscoveryAgent::QBluetoothServiceDiscoveryAgent(
const QBluetoothAddress &deviceAdapter, QObject *parent)
151 d_ptr(
new QBluetoothServiceDiscoveryAgentPrivate(
this, deviceAdapter))
153 if (!deviceAdapter.isNull()) {
154 const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices();
155 for (
const QBluetoothHostInfo &hostInfo : localDevices) {
156 if (hostInfo.address() == deviceAdapter)
159 d_ptr->error = InvalidBluetoothAdapterError;
160 d_ptr->errorString = tr(
"Invalid Bluetooth adapter address");
295void QBluetoothServiceDiscoveryAgent::start(DiscoveryMode mode)
297 Q_D(QBluetoothServiceDiscoveryAgent);
298#ifdef QT_OSX_BLUETOOTH
300 DarwinBluetooth::qt_test_iobluetooth_runloop();
303 if (d->discoveryState() == QBluetoothServiceDiscoveryAgentPrivate::Inactive
304 && d->error != InvalidBluetoothAdapterError) {
308 d->foundHostAdapterPath.clear();
310 d->setDiscoveryMode(mode);
312 d->error = QBluetoothServiceDiscoveryAgent::NoError;
313 d->errorString.clear();
314 if (d->deviceAddress.isNull()) {
315 d->startDeviceDiscovery();
317 d->discoveredDevices << QBluetoothDeviceInfo(d->deviceAddress, QString(), 0);
318 d->startServiceDiscovery();
327void QBluetoothServiceDiscoveryAgent::stop()
329 Q_D(QBluetoothServiceDiscoveryAgent);
331 if (d->error == InvalidBluetoothAdapterError || !isActive())
334 switch (d->discoveryState()) {
335 case QBluetoothServiceDiscoveryAgentPrivate::DeviceDiscovery:
336 d->stopDeviceDiscovery();
338 case QBluetoothServiceDiscoveryAgentPrivate::ServiceDiscovery:
339 d->stopServiceDiscovery();
345 d->discoveredDevices.clear();
422 Q_Q(QBluetoothServiceDiscoveryAgent);
424 if (!deviceDiscoveryAgent) {
426 deviceDiscoveryAgent =
new QBluetoothDeviceDiscoveryAgent(m_deviceAdapterAddress, q);
428 deviceDiscoveryAgent =
new QBluetoothDeviceDiscoveryAgent(q);
430 QObject::connect(deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished,
432 this->_q_deviceDiscoveryFinished();
434 QObject::connect(deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered,
435 q, [
this](
const QBluetoothDeviceInfo &info){
436 this->_q_deviceDiscovered(info);
438 QObject::connect(deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::errorOccurred, q,
439 [
this](QBluetoothDeviceDiscoveryAgent::Error newError) {
440 this->_q_deviceDiscoveryError(newError);
444 setDiscoveryState(DeviceDiscovery);
446 deviceDiscoveryAgent->start(QBluetoothDeviceDiscoveryAgent::ClassicMethod);
473 if (deviceDiscoveryAgent->error() != QBluetoothDeviceDiscoveryAgent::NoError) {
475 error =
static_cast<QBluetoothServiceDiscoveryAgent::Error>(deviceDiscoveryAgent->error());
476 errorString = deviceDiscoveryAgent->errorString();
477 setDiscoveryState(Inactive);
478 Q_Q(QBluetoothServiceDiscoveryAgent);
479 emit q->errorOccurred(error);
484 delete deviceDiscoveryAgent;
485 deviceDiscoveryAgent =
nullptr;
502 error =
static_cast<QBluetoothServiceDiscoveryAgent::Error>(newError);
503 errorString = deviceDiscoveryAgent->errorString();
507 deviceDiscoveryAgent->disconnect();
509 deviceDiscoveryAgent->stop();
510 delete deviceDiscoveryAgent;
511 deviceDiscoveryAgent =
nullptr;
513 setDiscoveryState(Inactive);
514 Q_Q(QBluetoothServiceDiscoveryAgent);
515 emit q->errorOccurred(error);