Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qbluetoothdevicediscoveryagent.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
7#include <QtCore/qloggingcategory.h>
8
10
12
13
169
183 const QBluetoothAddress &deviceAdapter, QObject *parent) :
184 QObject(parent),
185 d_ptr(new QBluetoothDeviceDiscoveryAgentPrivate(deviceAdapter, this))
186{
187 if (!deviceAdapter.isNull()) {
188 const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices();
189 for (const QBluetoothHostInfo &hostInfo : localDevices) {
190 if (hostInfo.address() == deviceAdapter)
191 return;
192 }
193 d_ptr->lastError = InvalidBluetoothAdapterError;
194 d_ptr->errorString = tr("Invalid Bluetooth adapter address");
195 }
196}
197
205
209QList<QBluetoothDeviceInfo> QBluetoothDeviceDiscoveryAgent::discoveredDevices() const
210{
212 return d->discoveredDevices;
213}
214
236{
238
239 // cannot deliberately turn it off
240 if (timeout < 0) {
241 qCDebug(QT_BT) << "The Bluetooth Low Energy device discovery timeout cannot be negative.";
242 return;
243 }
244
245 if (d->lowEnergySearchTimeout < 0) {
246 qCDebug(QT_BT) << "The Bluetooth Low Energy device discovery timeout cannot be "
247 "set on a backend which does not support this feature.";
248 return;
249 }
250
251 d->lowEnergySearchTimeout = timeout;
252}
253
264{
266 return d->lowEnergySearchTimeout;
267}
268
293
311{
312 if (methods == NoMethod)
313 return;
314
315 DiscoveryMethods supported =
317
319 if (!((supported & methods) == methods)) {
320 d->lastError = UnsupportedDiscoveryMethod;
321 d->errorString = QBluetoothDeviceDiscoveryAgent::tr("One or more device discovery methods "
322 "are not supported on this platform");
323 emit errorOccurred(d->lastError);
324 return;
325 }
326
327 if (!isActive())
328 d->start(methods);
329}
330
338{
340 if (isActive() && d->lastError != InvalidBluetoothAdapterError)
341 d->stop();
342}
343
345{
347 return d->isActive();
348}
349
361
368{
370 return d->errorString;
371}
372
374
375#include "moc_qbluetoothdevicediscoveryagent.cpp"
static JNINativeMethod methods[]
\inmodule QtBluetooth
static DiscoveryMethods supportedDiscoveryMethods()
This function returns the discovery methods supported by the current platform.
void errorOccurred(QBluetoothDeviceDiscoveryAgent::Error error)
This signal is emitted when an error occurs during Bluetooth device discovery.
int lowEnergyDiscoveryTimeout() const
Returns a timeout in milliseconds that is applied to the Bluetooth Low Energy device search.
void setLowEnergyDiscoveryTimeout(int msTimeout)
Sets the maximum search time for Bluetooth Low Energy device search to timeout in milliseconds.
QString errorString() const
Returns a human-readable description of the last error.
~QBluetoothDeviceDiscoveryAgent()
Destructor for ~QBluetoothDeviceDiscoveryAgent()
void start()
Starts Bluetooth device discovery, if it is not already started.
QList< QBluetoothDeviceInfo > discoveredDevices() const
Returns a list of all discovered Bluetooth devices.
bool isActive() const
Returns true if the agent is currently discovering Bluetooth devices, otherwise returns false.
Error error() const
Returns the last error.
QBluetoothDeviceDiscoveryAgent(QObject *parent=nullptr)
Constructs a new Bluetooth device discovery agent with parent parent.
void stop()
Stops Bluetooth device discovery.
Error
Indicates all possible error conditions found during Bluetooth device discovery.
\inmodule QtBluetooth
static QList< QBluetoothHostInfo > allDevices()
Returns a list of all available local Bluetooth devices.
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
#define this
Definition dialogs.cpp:9
Combined button and popup list for selecting options.
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLbitfield GLuint64 timeout
[4]
#define tr(X)
#define emit