summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2018-08-14 11:08:18 +0200
committerOliver Wolff <oliver.wolff@qt.io>2018-08-15 07:56:46 +0000
commita0ade068004ad869d6235ae8d6cd5e2050bf765d (patch)
tree42c949ba2fa7fcd4ab5356293d1ef3cad1c436f6 /tests
parent84f0e76c647e7f09529b79525b2d4fbc698576d8 (diff)
Replace foreach with for loop and set QT_NO_FOREACH
To avoid unnecessary copies, const is used wherever possible. Change-Id: Ic743716512751cfd24fad5bd37c244b115dd26fe Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp9
-rw-r--r--tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp6
-rw-r--r--tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp2
-rw-r--r--tests/auto/qbluetoothtransfermanager/tst_qbluetoothtransfermanager.cpp13
-rw-r--r--tests/auto/qbluetoothtransferrequest/tst_qbluetoothtransferrequest.cpp6
-rw-r--r--tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp9
-rw-r--r--tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp2
-rw-r--r--tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp18
-rw-r--r--tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp11
-rw-r--r--tests/auto/qnearfieldmanager/tst_qnearfieldmanager.cpp2
-rw-r--r--tests/bttestui/btlocaldevice.cpp37
11 files changed, 64 insertions, 51 deletions
diff --git a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp
index 7ef78800..a0ff581c 100644
--- a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp
+++ b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp
@@ -186,12 +186,12 @@ static void dumpAttributeVariant(const QVariant &var, const QString indent)
if (var.userType() == qMetaTypeId<QBluetoothServiceInfo::Sequence>()) {
qDebug("%sSequence", indent.toLocal8Bit().constData());
const QBluetoothServiceInfo::Sequence *sequence = static_cast<const QBluetoothServiceInfo::Sequence *>(var.data());
- foreach (const QVariant &v, *sequence)
+ for (const QVariant &v : *sequence)
dumpAttributeVariant(v, indent + '\t');
} else if (var.userType() == qMetaTypeId<QBluetoothServiceInfo::Alternative>()) {
qDebug("%sAlternative", indent.toLocal8Bit().constData());
const QBluetoothServiceInfo::Alternative *alternative = static_cast<const QBluetoothServiceInfo::Alternative *>(var.data());
- foreach (const QVariant &v, *alternative)
+ for (const QVariant &v : *alternative)
dumpAttributeVariant(v, indent + '\t');
} else if (var.userType() == qMetaTypeId<QBluetoothUuid>()) {
QBluetoothUuid uuid = var.value<QBluetoothUuid>();
@@ -237,7 +237,8 @@ static void dumpAttributeVariant(const QVariant &var, const QString indent)
static inline void dumpServiceInfoAttributes(const QBluetoothServiceInfo &info)
{
- foreach (quint16 id, info.attributes()) {
+ const QList<quint16> attributes = info.attributes();
+ for (quint16 id : attributes) {
dumpAttributeVariant(info.attribute(id), QString("\t"));
}
}
@@ -254,7 +255,7 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscovery_data()
// Only need to test the first 5 live devices
int max = 5;
- foreach (const QBluetoothDeviceInfo &info, devices) {
+ for (const QBluetoothDeviceInfo &info : qAsConst(devices)) {
if (info.isCached())
continue;
QTest::newRow("default filter") << info << QList<QBluetoothUuid>()
diff --git a/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp b/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp
index eb7ce85a..ae8cf5d0 100644
--- a/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp
+++ b/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp
@@ -132,7 +132,7 @@ void tst_QBluetoothServiceInfo::tst_construction()
QCOMPARE(serviceInfo.serverChannel(), -1);
QCOMPARE(serviceInfo.protocolServiceMultiplexer(), -1);
- foreach (QBluetoothUuid::ProtocolUuid u, protUuids)
+ for (QBluetoothUuid::ProtocolUuid u : qAsConst(protUuids))
QCOMPARE(serviceInfo.protocolDescriptor(u).count(), 0);
}
@@ -166,9 +166,9 @@ void tst_QBluetoothServiceInfo::tst_construction()
QCOMPARE(copyInfo.device().address(), alternatedeviceInfo.address());
QCOMPARE(serviceInfo.device().address(), alternatedeviceInfo.address());
- foreach (QBluetoothUuid::ProtocolUuid u, protUuids)
+ for (QBluetoothUuid::ProtocolUuid u : qAsConst(protUuids))
QCOMPARE(serviceInfo.protocolDescriptor(u).count(), 0);
- foreach (QBluetoothUuid::ProtocolUuid u, protUuids)
+ for (QBluetoothUuid::ProtocolUuid u : qAsConst(protUuids))
QCOMPARE(copyInfo.protocolDescriptor(u).count(), 0);
}
}
diff --git a/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp b/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp
index fa4629ac..05bc1a0f 100644
--- a/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp
+++ b/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp
@@ -377,7 +377,7 @@ void tst_QBluetoothSocket::tst_clientCommunication()
{
/* Send line by line with event loop */
- foreach (const QString &line, data) {
+ for (const QString &line : qAsConst(data)) {
QSignalSpy readyReadSpy(&socket, SIGNAL(readyRead()));
QSignalSpy bytesWrittenSpy(&socket, SIGNAL(bytesWritten(qint64)));
diff --git a/tests/auto/qbluetoothtransfermanager/tst_qbluetoothtransfermanager.cpp b/tests/auto/qbluetoothtransfermanager/tst_qbluetoothtransfermanager.cpp
index f69644c6..6b0481a5 100644
--- a/tests/auto/qbluetoothtransfermanager/tst_qbluetoothtransfermanager.cpp
+++ b/tests/auto/qbluetoothtransfermanager/tst_qbluetoothtransfermanager.cpp
@@ -143,14 +143,15 @@ void tst_QBluetoothTransferManager::tst_request()
QFETCH(tst_QBluetoothTransferManager_QParameterMap, parameters);
QBluetoothTransferRequest transferRequest(address);
- foreach (QBluetoothTransferRequest::Attribute key, parameters.keys())
+ const QList<QBluetoothTransferRequest::Attribute> attributes = parameters.keys();
+ for (QBluetoothTransferRequest::Attribute key : attributes)
QCOMPARE(transferRequest.attribute(key), QVariant());
- foreach (QBluetoothTransferRequest::Attribute key, parameters.keys())
+ for (QBluetoothTransferRequest::Attribute key : attributes)
transferRequest.setAttribute((QBluetoothTransferRequest::Attribute)key, parameters[key]);
QCOMPARE(transferRequest.address(), address);
- foreach (QBluetoothTransferRequest::Attribute key, parameters.keys())
+ for (QBluetoothTransferRequest::Attribute key : attributes)
QCOMPARE(transferRequest.attribute(key), parameters[key]);
//test copy constructor
@@ -158,17 +159,17 @@ void tst_QBluetoothTransferManager::tst_request()
QVERIFY(constructorCopy == transferRequest);
QVERIFY(!(constructorCopy != transferRequest));
QCOMPARE(constructorCopy.address(), address);
- foreach (QBluetoothTransferRequest::Attribute key, parameters.keys())
+ for (QBluetoothTransferRequest::Attribute key : attributes)
QCOMPARE(constructorCopy.attribute(key), parameters[key]);
//test assignment operator
QBluetoothTransferRequest request;
QVERIFY(request.address().isNull());
- foreach (QBluetoothTransferRequest::Attribute key, parameters.keys())
+ for (QBluetoothTransferRequest::Attribute key : attributes)
QCOMPARE(request.attribute(key), QVariant());
request = transferRequest;
QCOMPARE(request.address(), address);
- foreach (QBluetoothTransferRequest::Attribute key, parameters.keys())
+ for (QBluetoothTransferRequest::Attribute key : attributes)
QCOMPARE(request.attribute(key), parameters[key]);
//test that it's a true and independent copy
diff --git a/tests/auto/qbluetoothtransferrequest/tst_qbluetoothtransferrequest.cpp b/tests/auto/qbluetoothtransferrequest/tst_qbluetoothtransferrequest.cpp
index 1a8a8e52..dcf2c95b 100644
--- a/tests/auto/qbluetoothtransferrequest/tst_qbluetoothtransferrequest.cpp
+++ b/tests/auto/qbluetoothtransferrequest/tst_qbluetoothtransferrequest.cpp
@@ -98,7 +98,8 @@ void tst_QBluetoothTransferRequest::tst_construction()
QBluetoothTransferRequest transferRequest(address);
- foreach (int key, parameters.keys()) {
+ const QList<int> keys = parameters.keys();
+ for (const int key : keys) {
transferRequest.setAttribute((QBluetoothTransferRequest::Attribute)key, parameters[key]);
QCOMPARE(parameters[key], transferRequest.attribute((QBluetoothTransferRequest::Attribute)key));
}
@@ -123,7 +124,8 @@ void tst_QBluetoothTransferRequest::tst_assignment()
QBluetoothTransferRequest transferRequest(address);
- foreach (int key, parameters.keys()) {
+ const QList<int> keys = parameters.keys();
+ for (const int key : keys) {
transferRequest.setAttribute((QBluetoothTransferRequest::Attribute)key, parameters[key]);
}
diff --git a/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp b/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp
index e0513cea..1862af7f 100644
--- a/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp
+++ b/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp
@@ -114,7 +114,7 @@ void tst_QLowEnergyCharacteristic::initTestCase()
// find first service with descriptor
QLowEnergyController *controller = 0;
- foreach (const QBluetoothDeviceInfo &remoteDevice, remoteLeDevices) {
+ for (const QBluetoothDeviceInfo &remoteDevice : qAsConst(remoteLeDevices)) {
controller = new QLowEnergyController(remoteDevice, this);
qDebug() << "Connecting to" << remoteDevice.name()
<< remoteDevice.address() << remoteDevice.deviceUuid();
@@ -138,7 +138,8 @@ void tst_QLowEnergyCharacteristic::initTestCase()
QCOMPARE(stateSpy.at(1).at(0).value<QLowEnergyController::ControllerState>(),
QLowEnergyController::DiscoveredState);
- foreach (const QBluetoothUuid &leServiceUuid, controller->services()) {
+ const QList<QBluetoothUuid> leServiceUuids = controller->services();
+ for (const QBluetoothUuid &leServiceUuid : leServiceUuids) {
QLowEnergyService *leService = controller->createServiceObject(leServiceUuid, this);
if (!leService)
continue;
@@ -147,8 +148,8 @@ void tst_QLowEnergyCharacteristic::initTestCase()
QTRY_VERIFY_WITH_TIMEOUT(
leService->state() == QLowEnergyService::ServiceDiscovered, 10000);
- QList<QLowEnergyCharacteristic> chars = leService->characteristics();
- foreach (const QLowEnergyCharacteristic &ch, chars) {
+ const QList<QLowEnergyCharacteristic> chars = leService->characteristics();
+ for (const QLowEnergyCharacteristic &ch : chars) {
if (!ch.descriptors().isEmpty()) {
globalService = leService;
globalControl = controller;
diff --git a/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp b/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp
index 30b2fb75..f3a0e9a4 100644
--- a/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp
+++ b/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp
@@ -674,7 +674,7 @@ void TestQLowEnergyControllerGattServer::serviceData()
const auto inUuids = QSet<QBluetoothUuid>() << descData.uuid() << descData2.uuid()
<< descData3.uuid();
QSet<QBluetoothUuid> outUuids;
- foreach (const QLowEnergyDescriptor &desc, descriptors)
+ for (const QLowEnergyDescriptor &desc : descriptors)
outUuids << desc.uuid();
QCOMPARE(inUuids, outUuids);
diff --git a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp
index 53c2f754..b175ddd0 100644
--- a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp
+++ b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp
@@ -159,7 +159,8 @@ void tst_QLowEnergyController::initTestCase()
bool deviceFound = false;
devAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
QTRY_VERIFY_WITH_TIMEOUT(finishedSpy.count() > 0, 30000);
- foreach (const QBluetoothDeviceInfo &info, devAgent->discoveredDevices()) {
+ const QList<QBluetoothDeviceInfo> infos = devAgent->discoveredDevices();
+ for (const QBluetoothDeviceInfo &info : infos) {
#ifndef Q_OS_MAC
if (info.address() == remoteDevice) {
#else
@@ -343,7 +344,7 @@ void tst_QLowEnergyController::tst_connect()
listing.append(v.value<QBluetoothUuid>());
}
- foreach (const QBluetoothUuid &uuid, foundServices) {
+ for (const QBluetoothUuid &uuid : qAsConst(foundServices)) {
QVERIFY2(listing.contains(uuid),
uuid.toString().toLatin1());
@@ -361,7 +362,7 @@ void tst_QLowEnergyController::tst_connect()
QVERIFY(!control.createServiceObject(QBluetoothUuid(QBluetoothUuid::DeviceName)));
// initiate characteristic discovery
- foreach (QLowEnergyService *service, savedReferences) {
+ for (QLowEnergyService *service : qAsConst(savedReferences)) {
qDebug() << "Discovering" << service->serviceUuid();
QSignalSpy stateSpy(service,
SIGNAL(stateChanged(QLowEnergyService::ServiceState)));
@@ -378,7 +379,7 @@ void tst_QLowEnergyController::tst_connect()
}
// ensure that related service objects share same state
- foreach (QLowEnergyService* originalService, savedReferences) {
+ for (QLowEnergyService* originalService : qAsConst(savedReferences)) {
QLowEnergyService *newService = control.createServiceObject(
originalService->serviceUuid());
QVERIFY(newService);
@@ -398,7 +399,7 @@ void tst_QLowEnergyController::tst_connect()
} else {
QCOMPARE(disconnectedSpy.count(), 1);
// after disconnect all service references must be invalid
- foreach (const QLowEnergyService *entry, savedReferences) {
+ for (const QLowEnergyService *entry : qAsConst(savedReferences)) {
const QBluetoothUuid &uuid = entry->serviceUuid();
QVERIFY2(entry->state() == QLowEnergyService::InvalidService,
uuid.toString().toLatin1());
@@ -1208,7 +1209,7 @@ void tst_QLowEnergyController::verifyServiceProperties(
} else if (info->serviceUuid() ==
QBluetoothUuid(QString("f000aa40-0451-4000-b000-000000000000"))) {
qDebug() << "Verifying Pressure";
- QList<QLowEnergyCharacteristic> chars = info->characteristics();
+ const QList<QLowEnergyCharacteristic> chars = info->characteristics();
QVERIFY(chars.count() >= 3);
// Pressure Data
@@ -1271,7 +1272,7 @@ void tst_QLowEnergyController::verifyServiceProperties(
//calibration and period characteristic are swapped, ensure we don't depend on their order
QLowEnergyCharacteristic calibration, period;
- foreach (const QLowEnergyCharacteristic &ch, chars) {
+ for (const QLowEnergyCharacteristic &ch : chars) {
//find calibration characteristic
if (ch.uuid() == QBluetoothUuid(QString("f000aa43-0451-4000-b000-000000000000")))
calibration = ch;
@@ -1660,7 +1661,8 @@ bool tst_QLowEnergyController::verifyClientCharacteristicValue(const QByteArray
void tst_QLowEnergyController::tst_defaultBehavior()
{
QList<QBluetoothAddress> foundAddresses;
- foreach (const QBluetoothHostInfo &info, QBluetoothLocalDevice::allDevices())
+ const QList<QBluetoothHostInfo> infos = QBluetoothLocalDevice::allDevices();
+ for (const QBluetoothHostInfo &info : infos)
foundAddresses.append(info.address());
const QBluetoothAddress randomAddress("11:22:33:44:55:66");
diff --git a/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp b/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp
index e6728eab..b6ab0e53 100644
--- a/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp
+++ b/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp
@@ -105,7 +105,7 @@ void tst_QLowEnergyDescriptor::initTestCase()
// find first service with descriptor
QLowEnergyController *controller = 0;
- foreach (const QBluetoothDeviceInfo& remoteDeviceInfo, remoteLeDeviceInfos) {
+ for (const QBluetoothDeviceInfo& remoteDeviceInfo : qAsConst(remoteLeDeviceInfos)) {
controller = new QLowEnergyController(remoteDeviceInfo, this);
qDebug() << "Connecting to" << remoteDeviceInfo.address();
controller->connectToDevice();
@@ -128,7 +128,8 @@ void tst_QLowEnergyDescriptor::initTestCase()
QCOMPARE(stateSpy.at(1).at(0).value<QLowEnergyController::ControllerState>(),
QLowEnergyController::DiscoveredState);
- foreach (const QBluetoothUuid &leServiceUuid, controller->services()) {
+ const QList<QBluetoothUuid> leServiceUuids = controller->services();
+ for (const QBluetoothUuid &leServiceUuid : leServiceUuids) {
QLowEnergyService *leService = controller->createServiceObject(leServiceUuid, this);
if (!leService)
continue;
@@ -137,8 +138,8 @@ void tst_QLowEnergyDescriptor::initTestCase()
QTRY_VERIFY_WITH_TIMEOUT(
leService->state() == QLowEnergyService::ServiceDiscovered, 10000);
- QList<QLowEnergyCharacteristic> chars = leService->characteristics();
- foreach (const QLowEnergyCharacteristic &ch, chars) {
+ const QList<QLowEnergyCharacteristic> chars = leService->characteristics();
+ for (const QLowEnergyCharacteristic &ch : chars) {
if (!ch.descriptors().isEmpty()) {
globalService = leService;
globalControl = controller;
@@ -239,7 +240,7 @@ void tst_QLowEnergyDescriptor::tst_assignCompare()
QList<QLowEnergyDescriptor> targets;
const QList<QLowEnergyCharacteristic> chars = globalService->characteristics();
- foreach (const QLowEnergyCharacteristic &ch, chars) {
+ for (const QLowEnergyCharacteristic &ch : chars) {
if (!ch.descriptors().isEmpty()) {
targets = ch.descriptors();
break;
diff --git a/tests/auto/qnearfieldmanager/tst_qnearfieldmanager.cpp b/tests/auto/qnearfieldmanager/tst_qnearfieldmanager.cpp
index d5b8720f..c3c457e9 100644
--- a/tests/auto/qnearfieldmanager/tst_qnearfieldmanager.cpp
+++ b/tests/auto/qnearfieldmanager/tst_qnearfieldmanager.cpp
@@ -205,7 +205,7 @@ void tst_QNearFieldManager::registerNdefMessageHandler_type()
const QNdefMessage message = messageSpy.first().at(0).value<QNdefMessage>();
bool hasRecord = false;
- foreach (const QNdefRecord &record, message) {
+ for (const QNdefRecord &record : message) {
if (record.typeNameFormat() == typeNameFormat && record.type() == type) {
hasRecord = true;
break;
diff --git a/tests/bttestui/btlocaldevice.cpp b/tests/bttestui/btlocaldevice.cpp
index 77696853..54de57ca 100644
--- a/tests/bttestui/btlocaldevice.cpp
+++ b/tests/bttestui/btlocaldevice.cpp
@@ -329,7 +329,8 @@ void BtLocalDevice::stopServiceDiscovery()
void BtLocalDevice::serviceDiscovered(const QBluetoothServiceInfo &info)
{
QStringList classIds;
- foreach (const QBluetoothUuid &uuid, info.serviceClassUuids())
+ const QList<QBluetoothUuid> uuids = info.serviceClassUuids();
+ for (const QBluetoothUuid &uuid : uuids)
classIds.append(uuid.toString());
qDebug() << "$$ Found new service" << info.device().address().toString()
<< info.serviceUuid() << info.serviceName() << info.serviceDescription() << classIds;
@@ -347,7 +348,7 @@ void BtLocalDevice::serviceDiscovered(const QBluetoothServiceInfo &info)
{
//This is here to detect the test server for SPP testing later on
bool alreadyKnown = false;
- foreach (const QBluetoothServiceInfo& found, foundTestServers) {
+ for (const QBluetoothServiceInfo& found : qAsConst(foundTestServers)) {
if (found.device().address() == info.device().address()) {
alreadyKnown = true;
break;
@@ -384,24 +385,24 @@ void BtLocalDevice::dumpServiceDiscovery()
if (deviceAgent) {
qDebug() << "Device Discovery active:" << deviceAgent->isActive();
qDebug() << "Error:" << deviceAgent->error() << deviceAgent->errorString();
- QList<QBluetoothDeviceInfo> list = deviceAgent->discoveredDevices();
+ const QList<QBluetoothDeviceInfo> list = deviceAgent->discoveredDevices();
qDebug() << "Discovered Devices:" << list.count();
- foreach (const QBluetoothDeviceInfo &info, list)
+ for (const QBluetoothDeviceInfo &info : list)
qDebug() << info.name() << info.address().toString() << info.rssi();
}
if (serviceAgent) {
qDebug() << "Service Discovery active:" << serviceAgent->isActive();
qDebug() << "Error:" << serviceAgent->error() << serviceAgent->errorString();
- QList<QBluetoothServiceInfo> list = serviceAgent->discoveredServices();
+ const QList<QBluetoothServiceInfo> list = serviceAgent->discoveredServices();
qDebug() << "Discovered Services:" << list.count();
- foreach (const QBluetoothServiceInfo &i, list) {
+ for (const QBluetoothServiceInfo &i : list) {
qDebug() << i.device().address().toString() << i.device().name() << i.serviceName();
}
qDebug() << "###### TestServer offered by:";
- foreach (const QBluetoothServiceInfo& found, foundTestServers) {
+ for (const QBluetoothServiceInfo& found : qAsConst(foundTestServers)) {
qDebug() << found.device().name() << found.device().address().toString();
}
}
@@ -449,7 +450,7 @@ void BtLocalDevice::closeSocket()
if (!serverSockets.isEmpty()) {
qDebug() << "###### Closing server sockets";
- foreach (QBluetoothSocket *s, serverSockets)
+ for (QBluetoothSocket *s : serverSockets)
s->close();
}
}
@@ -463,7 +464,7 @@ void BtLocalDevice::abortSocket()
if (!serverSockets.isEmpty()) {
qDebug() << "###### Closing server sockets";
- foreach (QBluetoothSocket *s, serverSockets)
+ for (QBluetoothSocket *s : serverSockets)
s->abort();
}
}
@@ -526,7 +527,7 @@ void BtLocalDevice::writeData()
if (socket && socket->state() == QBluetoothSocket::ConnectedState) {
socket->write(testData);
}
- foreach (QBluetoothSocket* client, serverSockets) {
+ for (QBluetoothSocket* client : serverSockets) {
client->write(testData);
}
}
@@ -728,7 +729,7 @@ void BtLocalDevice::dumpServerInformation()
//server->setSecurityFlags(secFlag);
- foreach (const QBluetoothSocket *client, serverSockets) {
+ for (const QBluetoothSocket *client : qAsConst(serverSockets)) {
qDebug() << "##" << client->localAddress().toString()
<< client->localName() << client->localPort();
qDebug() << "##" << client->peerAddress().toString()
@@ -756,9 +757,9 @@ void BtLocalDevice::dumpInformation()
{
qDebug() << "###### default local device";
dumpLocalDevice(localDevice);
- QList<QBluetoothHostInfo> list = QBluetoothLocalDevice::allDevices();
+ const QList<QBluetoothHostInfo> list = QBluetoothLocalDevice::allDevices();
qDebug() << "Found local devices: " << list.count();
- foreach (const QBluetoothHostInfo &info, list) {
+ for (const QBluetoothHostInfo &info : list) {
qDebug() << " " << info.address().toString() << " " <<info.name();
}
@@ -778,13 +779,17 @@ void BtLocalDevice::dumpInformation()
qDebug() << "###### Bonding state with" << address.toString() << ": " << localDevice->pairingStatus(address);
qDebug() << "###### Connected Devices";
- foreach (const QBluetoothAddress &addr, localDevice->connectedDevices())
+ const QList<QBluetoothAddress> connectedDevices = localDevice->connectedDevices();
+ for (const QBluetoothAddress &addr : connectedDevices)
qDebug() << " " << addr.toString();
qDebug() << "###### Discovered Devices";
- if (deviceAgent)
- foreach (const QBluetoothDeviceInfo &info, deviceAgent->discoveredDevices())
+ if (deviceAgent) {
+ const QList<QBluetoothDeviceInfo> devices = deviceAgent->discoveredDevices();
+ for (const QBluetoothDeviceInfo &info : devices) {
deviceDiscovered(info);
+ }
+ }
QBluetoothDeviceDiscoveryAgent invalidAgent(QBluetoothAddress("11:22:33:44:55:66"));
invalidAgent.start();