diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2018-08-14 11:08:18 +0200 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2018-08-15 07:56:46 +0000 |
commit | a0ade068004ad869d6235ae8d6cd5e2050bf765d (patch) | |
tree | 42c949ba2fa7fcd4ab5356293d1ef3cad1c436f6 | |
parent | 84f0e76c647e7f09529b79525b2d4fbc698576d8 (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>
58 files changed, 205 insertions, 152 deletions
diff --git a/examples/bluetooth/btchat/chatserver.cpp b/examples/bluetooth/btchat/chatserver.cpp index e4293c75..5d59cd77 100644 --- a/examples/bluetooth/btchat/chatserver.cpp +++ b/examples/bluetooth/btchat/chatserver.cpp @@ -154,7 +154,7 @@ void ChatServer::sendMessage(const QString &message) { QByteArray text = message.toUtf8() + '\n'; - foreach (QBluetoothSocket *socket, clientSockets) + for (QBluetoothSocket *socket : qAsConst(clientSockets)) socket->write(text); } //! [sendMessage] diff --git a/examples/bluetooth/lowenergyscanner/characteristicinfo.cpp b/examples/bluetooth/lowenergyscanner/characteristicinfo.cpp index 58f91f5d..f64ddf79 100644 --- a/examples/bluetooth/lowenergyscanner/characteristicinfo.cpp +++ b/examples/bluetooth/lowenergyscanner/characteristicinfo.cpp @@ -76,7 +76,8 @@ QString CharacteristicInfo::getName() const return name; // find descriptor with CharacteristicUserDescription - foreach (const QLowEnergyDescriptor &descriptor, m_characteristic.descriptors()) { + const QList<QLowEnergyDescriptor> descriptors = m_characteristic.descriptors(); + for (const QLowEnergyDescriptor &descriptor : descriptors) { if (descriptor.type() == QBluetoothUuid::CharacteristicUserDescription) { name = descriptor.value(); break; diff --git a/examples/bluetooth/lowenergyscanner/device.cpp b/examples/bluetooth/lowenergyscanner/device.cpp index 2ae30c16..cfbf4596 100644 --- a/examples/bluetooth/lowenergyscanner/device.cpp +++ b/examples/bluetooth/lowenergyscanner/device.cpp @@ -256,7 +256,7 @@ void Device::connectToService(const QString &uuid) //discovery already done const QList<QLowEnergyCharacteristic> chars = service->characteristics(); - foreach (const QLowEnergyCharacteristic &ch, chars) { + for (const QLowEnergyCharacteristic &ch : chars) { CharacteristicInfo *cInfo = new CharacteristicInfo(ch); m_characteristics.append(cInfo); } @@ -326,7 +326,7 @@ void Device::serviceDetailsDiscovered(QLowEnergyService::ServiceState newState) //! [les-chars] const QList<QLowEnergyCharacteristic> chars = service->characteristics(); - foreach (const QLowEnergyCharacteristic &ch, chars) { + for (const QLowEnergyCharacteristic &ch : chars) { CharacteristicInfo *cInfo = new CharacteristicInfo(ch); m_characteristics.append(cInfo); } diff --git a/examples/nfc/annotatedurl/annotatedurl.cpp b/examples/nfc/annotatedurl/annotatedurl.cpp index 0e6b58fa..acd401f2 100644 --- a/examples/nfc/annotatedurl/annotatedurl.cpp +++ b/examples/nfc/annotatedurl/annotatedurl.cpp @@ -143,7 +143,7 @@ void AnnotatedUrl::handleMessage(const QNdefMessage &message, QNearFieldTarget * QPixmap pixmap; //! [handleMessage 2] - foreach (const QNdefRecord &record, message) { + for (const QNdefRecord &record : message) { if (record.isRecordType<QNdefNfcTextRecord>()) { QNdefNfcTextRecord textRecord(record); diff --git a/examples/nfc/ndefeditor/mainwindow.cpp b/examples/nfc/ndefeditor/mainwindow.cpp index 38865b88..869f1790 100644 --- a/examples/nfc/ndefeditor/mainwindow.cpp +++ b/examples/nfc/ndefeditor/mainwindow.cpp @@ -266,7 +266,7 @@ void MainWindow::ndefMessageRead(const QNdefMessage &message) { clearMessage(); - foreach (const QNdefRecord &record, message) { + for (const QNdefRecord &record : message) { if (record.isRecordType<QNdefNfcTextRecord>()) { addRecord<TextRecordEditor>(ui, record); } else if (record.isRecordType<QNdefNfcUriRecord>()) { diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro index 72208a87..193ed217 100644 --- a/src/bluetooth/bluetooth.pro +++ b/src/bluetooth/bluetooth.pro @@ -1,6 +1,6 @@ TARGET = QtBluetooth QT = core core-private - +DEFINES += QT_NO_FOREACH QMAKE_DOCS = $$PWD/doc/qtbluetooth.qdocconf OTHER_FILES += doc/src/*.qdoc # show .qdoc files in Qt Creator diff --git a/src/bluetooth/bluez/bluez5_helper.cpp b/src/bluetooth/bluez/bluez5_helper.cpp index f798088e..2beb533c 100644 --- a/src/bluetooth/bluez/bluez5_helper.cpp +++ b/src/bluetooth/bluez/bluez5_helper.cpp @@ -331,7 +331,8 @@ QtBluezDiscoveryManager::~QtBluezDiscoveryManager() { qCDebug(QT_BT_BLUEZ) << "Destroying QtBluezDiscoveryManager"; - foreach (const QString &adapterPath, d->references.keys()) { + const QList<QString> adapterPaths = d->references.keys(); + for (const QString &adapterPath : adapterPaths) { AdapterData *data = d->references.take(adapterPath); delete data->propteryListener; @@ -416,7 +417,8 @@ void QtBluezDiscoveryManager::unregisterDiscoveryInterest(const QString &adapter // if (d->references.isEmpty()) { // qCDebug(QT_BT_BLUEZ) << "No running registration"; // } else { -// foreach (const QString &path, d->references.keys()) { +// const QList<QString> paths = d->references.keys(); +// for (const QString &path : paths) { // qCDebug(QT_BT_BLUEZ) << path << "->" << d->references[path]->reference; // } // } @@ -536,7 +538,7 @@ QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok = if (wantedAddress.isNull()) return localAdapters.front().first; // -> return first found adapter - foreach (const AddressForPathType &pair, localAdapters) { + for (const AddressForPathType &pair : qAsConst(localAdapters)) { if (pair.second == wantedAddress) return pair.first; // -> found local adapter with wanted address } diff --git a/src/bluetooth/osx/osxbtobexsession.mm b/src/bluetooth/osx/osxbtobexsession.mm index e228d6db..9fbc2c12 100644 --- a/src/bluetooth/osx/osxbtobexsession.mm +++ b/src/bluetooth/osx/osxbtobexsession.mm @@ -537,14 +537,14 @@ QT_USE_NAMESPACE const OBEXConnectCommandResponseData *const response = &event->u.connectCommandResponseData; if (response->headerDataPtr && response->headerDataLength >= 2) { // 2 == 1 byte headerID + at least 1 byte headerValue ... - QList<OBEXHeader> headers(qt_bluetooth_headers(static_cast<const uint8_t *>(response->headerDataPtr), + const QList<OBEXHeader> headers(qt_bluetooth_headers(static_cast<const uint8_t *>(response->headerDataPtr), response->headerDataLength)); // ConnectionID is used when multiplexing OBEX connections // to identify which particular connection this object is // being sent on. When used, this _must_ be the first // header sent. - foreach (const OBEXHeader &header, headers) { + for (const OBEXHeader &header : headers) { if (header.headerID == kOBEXHeaderIDConnectionID) { connectionID = header.value.value<quint32>(); connectionIDFound = true; diff --git a/src/bluetooth/osx/osxbtsdpinquiry.mm b/src/bluetooth/osx/osxbtsdpinquiry.mm index a0bfdeef..6df2d16e 100644 --- a/src/bluetooth/osx/osxbtsdpinquiry.mm +++ b/src/bluetooth/osx/osxbtsdpinquiry.mm @@ -188,7 +188,7 @@ using namespace OSXBluetooth; return kIOReturnError; } - foreach (const QBluetoothUuid &qUuid, qtFilters) { + for (const QBluetoothUuid &qUuid : qtFilters) { ObjCStrongReference<IOBluetoothSDPUUID> uuid(iobluetooth_uuid(qUuid)); if (uuid) [array addObject:uuid]; diff --git a/src/bluetooth/osx/osxbtservicerecord.mm b/src/bluetooth/osx/osxbtservicerecord.mm index d12169bb..23d55d13 100644 --- a/src/bluetooth/osx/osxbtservicerecord.mm +++ b/src/bluetooth/osx/osxbtservicerecord.mm @@ -386,7 +386,7 @@ bool add_sequence_attribute(const QVariant &var, AttributeId key, NSMutableArray return false; const Sequence sequence(var.value<Sequence>()); - foreach (const QVariant &var, sequence) { + for (const QVariant &var : sequence) { if (var.canConvert<Sequence>()) { NSMutableArray *const nested = [NSMutableArray array]; add_sequence_attribute(var, key, nested); @@ -411,7 +411,7 @@ bool add_sequence_attribute(const QBluetoothServiceInfo &serviceInfo, AttributeI NSMutableArray *const list = [NSMutableArray array]; const Sequence sequence(var.value<Sequence>()); - foreach (const QVariant &element, sequence) { + for (const QVariant &element : sequence) { if (!add_sequence_attribute(element, key, list)) add_attribute(element, key, list); } @@ -433,7 +433,7 @@ Dictionary iobluetooth_service_dictionary(const QBluetoothServiceInfo &serviceIn dict.reset([[NSMutableDictionary alloc] init]); - foreach (quint16 key, attributeIds) { + for (quint16 key : attributeIds) { if (key == QSInfo::ProtocolDescriptorList) // We handle it in a special way. continue; // TODO: check if non-sequence QVariant still must be diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp index 5f142f1a..a9e35960 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp @@ -210,7 +210,7 @@ QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent( { if (!deviceAdapter.isNull()) { const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices(); - foreach (const QBluetoothHostInfo &hostInfo, localDevices) { + for (const QBluetoothHostInfo &hostInfo : localDevices) { if (hostInfo.address() == deviceAdapter) return; } diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp index 3cc3354a..3d09a4df 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp @@ -360,7 +360,9 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_deviceFound(const QString &addres if (dict.value(QStringLiteral("RSSI")).isValid()) device.setRssi(dict.value(QStringLiteral("RSSI")).toInt()); QList<QBluetoothUuid> uuids; - foreach (const QString &u, dict.value(QLatin1String("UUIDs")).toStringList()) + const QStringList uuidStrings + = dict.value(QLatin1String("UUIDs")).toStringList(); + for (const QString &u : uuidStrings) uuids.append(QBluetoothUuid(u)); device.setServiceUuids(uuids, QBluetoothDeviceInfo::DataIncomplete); device.setCached(dict.value(QStringLiteral("Cached")).toBool()); diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm index fed33bb2..4657da82 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm @@ -553,7 +553,7 @@ QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent( { if (!deviceAdapter.isNull()) { const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices(); - foreach (const QBluetoothHostInfo &hostInfo, localDevices) { + for (const QBluetoothHostInfo &hostInfo : localDevices) { if (hostInfo.address() == deviceAdapter) return; } diff --git a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp index c247f679..8612fd5c 100644 --- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp @@ -249,7 +249,8 @@ QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices() if (reply.isError()) return localDevices; - foreach (const QDBusObjectPath &path, reply.value()) { + const QList<QDBusObjectPath> paths = reply.value(); + for (const QDBusObjectPath &path : paths) { QBluetoothHostInfo hostinfo; OrgBluezAdapterInterface adapter(QStringLiteral("org.bluez"), path.path(), QDBusConnection::systemBus()); @@ -770,7 +771,8 @@ void QBluetoothLocalDevicePrivate::initializeAdapter() if (reply.isError()) return; - foreach (const QDBusObjectPath &path, reply.value()) { + const QList<QDBusObjectPath> paths = reply.value(); + for (const QDBusObjectPath &path : paths) { OrgBluezAdapterInterface *tmpAdapter = new OrgBluezAdapterInterface(QStringLiteral("org.bluez"), path.path(), QDBusConnection::systemBus()); @@ -1067,7 +1069,7 @@ void QBluetoothLocalDevicePrivate::_q_deviceCreated(const QDBusObjectPath &devic void QBluetoothLocalDevicePrivate::_q_deviceRemoved(const QDBusObjectPath &device) { - foreach (OrgBluezDeviceInterface *deviceInterface, devices) { + for (OrgBluezDeviceInterface *deviceInterface : qAsConst(devices)) { if (deviceInterface->path() == device.path()) { devices.remove(deviceInterface); delete deviceInterface; // deviceDisconnected is already emitted by _q_devicePropertyChanged @@ -1113,7 +1115,8 @@ void QBluetoothLocalDevicePrivate::createCache() qCWarning(QT_BT_BLUEZ) << reply.error().message(); return; } - foreach (const QDBusObjectPath &device, reply.value()) { + const QList<QDBusObjectPath> knownDevices = reply.value(); + for (const QDBusObjectPath &device : knownDevices) { OrgBluezDeviceInterface *deviceInterface = new OrgBluezDeviceInterface(QStringLiteral("org.bluez"), device.path(), diff --git a/src/bluetooth/qbluetoothserver_android.cpp b/src/bluetooth/qbluetoothserver_android.cpp index b001adb8..3c2cc507 100644 --- a/src/bluetooth/qbluetoothserver_android.cpp +++ b/src/bluetooth/qbluetoothserver_android.cpp @@ -142,7 +142,7 @@ bool QBluetoothServer::listen(const QBluetoothAddress &localAdapter, quint16 por if (!localAdapter.isNull()) { bool found = false; - foreach (const QBluetoothHostInfo &hostInfo, localDevices) { + for (const QBluetoothHostInfo &hostInfo : localDevices) { if (hostInfo.address() == localAdapter) { found = true; break; diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp index 05d62ab1..e24876e4 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp @@ -177,7 +177,7 @@ QBluetoothServiceDiscoveryAgent::QBluetoothServiceDiscoveryAgent(const QBluetoot { if (!deviceAdapter.isNull()) { const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices(); - foreach (const QBluetoothHostInfo &hostInfo, localDevices) { + for (const QBluetoothHostInfo &hostInfo : localDevices) { if (hostInfo.address() == deviceAdapter) return; } diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp index 51db091e..63601058 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp @@ -427,7 +427,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_fetchUuidsTimeout() QPair<QBluetoothDeviceInfo,QList<QBluetoothUuid> > pair; const QList<QBluetoothAddress> keys = sdpCache.keys(); - foreach (const QBluetoothAddress &key, keys) { + for (const QBluetoothAddress &key : keys) { pair = sdpCache.take(key); populateDiscoveredServices(pair.first, pair.second); } diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp index ea9f354b..82939c26 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp @@ -223,7 +223,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::runExternalSdpScan( // No filter implies PUBLIC_BROWSE_GROUP based SDP scan if (!uuidFilter.isEmpty()) { arguments << QLatin1String("-u"); // cmd line option for list of uuids - foreach (const QBluetoothUuid& uuid, uuidFilter) + for (const QBluetoothUuid& uuid : qAsConst(uuidFilter)) arguments << uuid.toString(); } @@ -286,14 +286,16 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_finishSdpScan(QBluetoothServiceD errorString = errorDescription; emit q->error(error); } else if (!xmlRecords.isEmpty() && discoveryState() != Inactive) { - foreach (const QString &record, xmlRecords) { + for (const QString &record : xmlRecords) { const QBluetoothServiceInfo serviceInfo = parseServiceXml(record); //apply uuidFilter if (!uuidFilter.isEmpty()) { bool serviceNameMatched = uuidFilter.contains(serviceInfo.serviceUuid()); bool serviceClassMatched = false; - foreach (const QBluetoothUuid &id, serviceInfo.serviceClassUuids()) { + const QList<QBluetoothUuid> serviceClassUuids + = serviceInfo.serviceClassUuids(); + for (const QBluetoothUuid &id : serviceClassUuids) { if (uuidFilter.contains(id)) { serviceClassMatched = true; break; @@ -519,7 +521,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::discoverServices(const QString &dev _q_serviceDiscoveryFinished(); } else { QString pattern; - foreach (const QBluetoothUuid &uuid, uuidFilter) + for (const QBluetoothUuid &uuid : qAsConst(uuidFilter)) pattern += uuid.toString().remove(QLatin1Char('{')).remove(QLatin1Char('}')) + QLatin1Char(' '); pattern = pattern.trimmed(); @@ -558,13 +560,13 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC return; } - ServiceMap map = reply.value(); + const ServiceMap map = reply.value(); qCDebug(QT_BT_BLUEZ) << "Parsing xml" << discoveredDevices.at(0).address().toString() << discoveredDevices.count() << map.count(); - foreach (const QString &record, reply.value()) { + for (const QString &record : map) { QBluetoothServiceInfo serviceInfo = parseServiceXml(record); if (!serviceInfo.isValid()) @@ -578,7 +580,8 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC // to our own naming resolution. if (serviceInfo.serviceName().isEmpty() && !serviceInfo.serviceClassUuids().isEmpty()) { - foreach (const QBluetoothUuid &classUuid, serviceInfo.serviceClassUuids()) { + const QList<QBluetoothUuid> classUuids = serviceInfo.serviceClassUuids(); + for (const QBluetoothUuid &classUuid : classUuids) { bool ok = false; QBluetoothUuid::ServiceClassUuid clsId = static_cast<QBluetoothUuid::ServiceClassUuid>(classUuid.toUInt16(&ok)); diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm index 1d0cc7da..61d3bcc2 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm +++ b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm @@ -441,7 +441,7 @@ QBluetoothServiceDiscoveryAgent::QBluetoothServiceDiscoveryAgent(const QBluetoot { if (!deviceAdapter.isNull()) { const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices(); - foreach (const QBluetoothHostInfo &hostInfo, localDevices) { + for (const QBluetoothHostInfo &hostInfo : localDevices) { if (hostInfo.address() == deviceAdapter) return; } diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp index 77310d01..09523c75 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp @@ -537,7 +537,9 @@ void QBluetoothServiceDiscoveryAgentPrivate::processFoundService(quint64 deviceA if (!uuidFilter.isEmpty()) { bool serviceNameMatched = uuidFilter.contains(info.serviceUuid()); bool serviceClassMatched = false; - for (const QBluetoothUuid &id : info.serviceClassUuids()) { + const QList<QBluetoothUuid> serviceClassUuids + = info.serviceClassUuids(); + for (const QBluetoothUuid &id : serviceClassUuids) { if (uuidFilter.contains(id)) { serviceClassMatched = true; break; @@ -553,7 +555,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::processFoundService(quint64 deviceA QBluetoothServiceInfo returnInfo(info); bool deviceFound; - for (const QBluetoothDeviceInfo &deviceInfo : discoveredDevices) { + for (const QBluetoothDeviceInfo &deviceInfo : qAsConst(discoveredDevices)) { if (deviceInfo.address().toUInt64() == deviceAddress) { deviceFound = true; returnInfo.setDevice(deviceInfo); @@ -576,7 +578,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::onScanFinished(quint64 deviceAddres { Q_Q(QBluetoothServiceDiscoveryAgent); bool deviceFound; - for (const QBluetoothDeviceInfo &deviceInfo : discoveredDevices) { + for (const QBluetoothDeviceInfo &deviceInfo : qAsConst(discoveredDevices)) { if (deviceInfo.address().toUInt64() == deviceAddress) { deviceFound = true; discoveredDevices.removeOne(deviceInfo); diff --git a/src/bluetooth/qbluetoothserviceinfo.cpp b/src/bluetooth/qbluetoothserviceinfo.cpp index d706e4a7..d98e616f 100644 --- a/src/bluetooth/qbluetoothserviceinfo.cpp +++ b/src/bluetooth/qbluetoothserviceinfo.cpp @@ -606,12 +606,12 @@ static void dumpAttributeVariant(QDebug dbg, const QVariant &var, const QString& } else if (var.userType() == qMetaTypeId<QBluetoothServiceInfo::Sequence>()) { dbg << QString::asprintf("%sSequence\n", indent.toUtf8().constData()); const QBluetoothServiceInfo::Sequence *sequence = static_cast<const QBluetoothServiceInfo::Sequence *>(var.data()); - foreach (const QVariant &v, *sequence) + for (const QVariant &v : *sequence) dumpAttributeVariant(dbg, v, indent + QLatin1Char('\t')); } else if (var.userType() == qMetaTypeId<QBluetoothServiceInfo::Alternative>()) { dbg << QString::asprintf("%sAlternative\n", indent.toUtf8().constData()); const QBluetoothServiceInfo::Alternative *alternative = static_cast<const QBluetoothServiceInfo::Alternative *>(var.data()); - foreach (const QVariant &v, *alternative) + for (const QVariant &v : *alternative) dumpAttributeVariant(dbg, v, indent + QLatin1Char('\t')); } break; @@ -626,7 +626,8 @@ QDebug operator<<(QDebug dbg, const QBluetoothServiceInfo &info) { QDebugStateSaver saver(dbg); dbg.noquote() << "\n"; - foreach (quint16 id, info.attributes()) { + QList<quint16> attributes = info.attributes(); + for (quint16 id : attributes) { dumpAttributeVariant(dbg, info.attribute(id), QStringLiteral("(%1)\t").arg(id)); } return dbg; @@ -637,7 +638,9 @@ QBluetoothServiceInfo::Sequence QBluetoothServiceInfoPrivate::protocolDescriptor if (!attributes.contains(QBluetoothServiceInfo::ProtocolDescriptorList)) return QBluetoothServiceInfo::Sequence(); - foreach (const QVariant &v, attributes.value(QBluetoothServiceInfo::ProtocolDescriptorList).value<QBluetoothServiceInfo::Sequence>()) { + const QBluetoothServiceInfo::Sequence sequence + = attributes.value(QBluetoothServiceInfo::ProtocolDescriptorList).value<QBluetoothServiceInfo::Sequence>(); + for (const QVariant &v : sequence) { QBluetoothServiceInfo::Sequence parameters = v.value<QBluetoothServiceInfo::Sequence>(); if (parameters.empty()) continue; diff --git a/src/bluetooth/qbluetoothserviceinfo_android.cpp b/src/bluetooth/qbluetoothserviceinfo_android.cpp index 0b46e11b..b0193f73 100644 --- a/src/bluetooth/qbluetoothserviceinfo_android.cpp +++ b/src/bluetooth/qbluetoothserviceinfo_android.cpp @@ -95,7 +95,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress& loca if (!localAdapter.isNull()) { bool found = false; - foreach (const QBluetoothHostInfo &hostInfo, localDevices) { + for (const QBluetoothHostInfo &hostInfo : localDevices) { if (hostInfo.address() == localAdapter) { found = true; break; diff --git a/src/bluetooth/qbluetoothserviceinfo_bluez.cpp b/src/bluetooth/qbluetoothserviceinfo_bluez.cpp index 87c715c4..312b5a7a 100644 --- a/src/bluetooth/qbluetoothserviceinfo_bluez.cpp +++ b/src/bluetooth/qbluetoothserviceinfo_bluez.cpp @@ -158,13 +158,13 @@ static void writeAttribute(QXmlStreamWriter *stream, const QVariant &attribute) stream->writeStartElement(QStringLiteral("sequence")); const QBluetoothServiceInfo::Sequence *sequence = static_cast<const QBluetoothServiceInfo::Sequence *>(attribute.data()); - foreach (const QVariant &v, *sequence) + for (const QVariant &v : *sequence) writeAttribute(stream, v); stream->writeEndElement(); } else if (attribute.userType() == qMetaTypeId<QBluetoothServiceInfo::Alternative>()) { const QBluetoothServiceInfo::Alternative *alternative = static_cast<const QBluetoothServiceInfo::Alternative *>(attribute.data()); - foreach (const QVariant &v, *alternative) + for (const QVariant &v : *alternative) writeAttribute(stream, v); stream->writeEndElement(); } diff --git a/src/bluetooth/qbluetoothserviceinfo_osx.mm b/src/bluetooth/qbluetoothserviceinfo_osx.mm index 755e85c9..27da70fc 100644 --- a/src/bluetooth/qbluetoothserviceinfo_osx.mm +++ b/src/bluetooth/qbluetoothserviceinfo_osx.mm @@ -359,12 +359,12 @@ static void dumpAttributeVariant(const QVariant &var, const QString indent) } else 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 + QLatin1Char('\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 + QLatin1Char('\t')); } break; @@ -375,7 +375,8 @@ static void dumpAttributeVariant(const QVariant &var, const QString indent) QDebug operator << (QDebug dbg, const QBluetoothServiceInfo &info) { - foreach (quint16 id, info.attributes()) { + const QList<quint16> attributes = info.attributes(); + for (quint16 id : attributes) { dumpAttributeVariant(info.attribute(id), QString::fromLatin1("(%1)\t").arg(id)); } return dbg; @@ -386,7 +387,9 @@ QBluetoothServiceInfo::Sequence QBluetoothServiceInfoPrivate::protocolDescriptor if (!attributes.contains(QBluetoothServiceInfo::ProtocolDescriptorList)) return QBluetoothServiceInfo::Sequence(); - foreach (const QVariant &v, attributes.value(QBluetoothServiceInfo::ProtocolDescriptorList).value<QBluetoothServiceInfo::Sequence>()) { + const QBluetoothServiceInfo::Sequence sequence + = attributes.value(QBluetoothServiceInfo::ProtocolDescriptorList).value<QBluetoothServiceInfo::Sequence>(); + for (const QVariant &v : sequence) { QBluetoothServiceInfo::Sequence parameters = v.value<QBluetoothServiceInfo::Sequence>(); if (parameters.empty()) continue; diff --git a/src/bluetooth/qbluetoothserviceinfo_winrt.cpp b/src/bluetooth/qbluetoothserviceinfo_winrt.cpp index 5400c001..df3e97b9 100644 --- a/src/bluetooth/qbluetoothserviceinfo_winrt.cpp +++ b/src/bluetooth/qbluetoothserviceinfo_winrt.cpp @@ -290,7 +290,7 @@ static ComPtr<IBuffer> bufferFromAttribute(const QVariant &attribute) HRESULT hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_DataWriter).Get(), &tmpWriter); Q_ASSERT_SUCCEEDED(hr); - foreach (const QVariant &v, *sequence) { + for (const QVariant &v : *sequence) { ComPtr<IBuffer> tmpBuffer = bufferFromAttribute(v); if (!tmpBuffer) { qCWarning(QT_BT_WINRT) << "Could not create buffer from attribute in sequence"; @@ -468,7 +468,8 @@ bool QBluetoothServiceInfoPrivate::writeSdpAttributes() ComPtr<IMap<UINT32, IBuffer *>> rawAttributes; hr = serviceProvider->get_SdpRawAttributes(&rawAttributes); Q_ASSERT_SUCCEEDED(hr); - for (quint16 key : attributes.keys()) { + const QList<quint16> keys = attributes.keys(); + for (quint16 key : keys) { // The SDP Class Id List and RFCOMM and L2CAP protocol descriptors are automatically // generated by the RfcommServiceProvider. Do not specify it in the SDP raw attribute map. if (key == QBluetoothServiceInfo::ServiceClassIds diff --git a/src/bluetooth/qleadvertiser_bluez.cpp b/src/bluetooth/qleadvertiser_bluez.cpp index bff5a590..47daed25 100644 --- a/src/bluetooth/qleadvertiser_bluez.cpp +++ b/src/bluetooth/qleadvertiser_bluez.cpp @@ -273,7 +273,8 @@ void QLeAdvertiserBluez::setServicesData(const QLowEnergyAdvertisingData &src, A QVector<quint16> services16; QVector<quint32> services32; QVector<quint128> services128; - foreach (const QBluetoothUuid &service, src.services()) { + const QList<QBluetoothUuid> services = src.services(); + for (const QBluetoothUuid &service : services) { bool ok; const quint16 service16 = service.toUInt16(&ok); if (ok) { @@ -393,7 +394,9 @@ void QLeAdvertiserBluez::setWhiteList() if (parameters().filterPolicy() == QLowEnergyAdvertisingParameters::IgnoreWhiteList) return; queueCommand(OcfLeClearWhiteList, QByteArray()); - foreach (const auto &addressInfo, parameters().whiteList()) { + const QList<QLowEnergyAdvertisingParameters::AddressInfo> whiteListInfos + = parameters().whiteList(); + for (const auto &addressInfo : whiteListInfos) { WhiteListParams commandParam; static_assert(sizeof commandParam == 7, "unexpected struct size"); commandParam.addrType = addressInfo.type; diff --git a/src/bluetooth/qlowenergycharacteristic.cpp b/src/bluetooth/qlowenergycharacteristic.cpp index a8b4c449..82db1c7b 100644 --- a/src/bluetooth/qlowenergycharacteristic.cpp +++ b/src/bluetooth/qlowenergycharacteristic.cpp @@ -380,7 +380,7 @@ QList<QLowEnergyDescriptor> QLowEnergyCharacteristic::descriptors() const std::sort(descriptorKeys.begin(), descriptorKeys.end()); - foreach (const QLowEnergyHandle descHandle, descriptorKeys) { + for (const QLowEnergyHandle descHandle : qAsConst(descriptorKeys)) { QLowEnergyDescriptor descriptor(d_ptr, data->handle, descHandle); result.append(descriptor); } diff --git a/src/bluetooth/qlowenergycharacteristicdata.cpp b/src/bluetooth/qlowenergycharacteristicdata.cpp index 9e0d69ad..700566a6 100644 --- a/src/bluetooth/qlowenergycharacteristicdata.cpp +++ b/src/bluetooth/qlowenergycharacteristicdata.cpp @@ -157,7 +157,7 @@ QList<QLowEnergyDescriptorData> QLowEnergyCharacteristicData::descriptors() cons void QLowEnergyCharacteristicData::setDescriptors(const QList<QLowEnergyDescriptorData> &descriptors) { d->descriptors.clear(); - foreach (const QLowEnergyDescriptorData &desc, descriptors) + for (const QLowEnergyDescriptorData &desc : descriptors) addDescriptor(desc); } diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp index 54665f7b..35d943fc 100644 --- a/src/bluetooth/qlowenergycontroller_android.cpp +++ b/src/bluetooth/qlowenergycontroller_android.cpp @@ -501,7 +501,7 @@ void QLowEnergyControllerPrivateAndroid::servicesDiscovered( if (errorCode == QLowEnergyController::NoError) { //Android delivers all services in one go const QStringList list = foundServices.split(QStringLiteral(" "), QString::SkipEmptyParts); - foreach (const QString &entry, list) { + for (const QString &entry : list) { const QBluetoothUuid service(entry); if (service.isNull()) return; @@ -550,7 +550,7 @@ void QLowEnergyControllerPrivateAndroid::serviceDetailsDiscoveryFinished( const QStringList list = javaIncludes.toString() .split(QStringLiteral(" "), QString::SkipEmptyParts); - foreach (const QString &entry, list) { + for (const QString &entry : list) { const QBluetoothUuid service(entry); if (service.isNull()) return; diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 502f42ad..7229821e 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -1215,7 +1215,7 @@ void QLowEnergyControllerPrivateBluez::processReply( lastHandle = parseReadByTypeIncludeDiscovery( &includedServices, &data[offset], elementLength); p->includedServices = includedServices; - foreach (const QBluetoothUuid &uuid, includedServices) { + for (const QBluetoothUuid &uuid : qAsConst(includedServices)) { if (serviceList.contains(uuid)) serviceList[uuid]->type |= QLowEnergyService::IncludedService; } @@ -2495,7 +2495,7 @@ void QLowEnergyControllerPrivateBluez::handleReadMultipleRequest(const QByteArra } const QVector<Attribute> results = getAttributes(handles.first(), handles.last()); QByteArray response(1, ATT_OP_READ_MULTIPLE_RESPONSE); - foreach (const Attribute &attr, results) { + for (const Attribute &attr : results) { const int error = checkReadPermissions(attr); if (error) { sendErrorResponse(packet.at(0), attr.handle, error); @@ -2577,7 +2577,7 @@ void QLowEnergyControllerPrivateBluez::updateLocalAttributeValue( QLowEnergyDescriptor &descriptor) { localAttributes[handle].value = value; - foreach (const auto &service, localServices) { + for (const auto &service : qAsConst(localServices)) { if (handle < service->startHandle || handle > service->endHandle) continue; for (auto charIt = service->characteristicList.begin(); @@ -2623,7 +2623,7 @@ void QLowEnergyControllerPrivateBluez::writeCharacteristicForPeripheral( = attribute.properties & QLowEnergyCharacteristic::Indicate; if (!hasNotifyProperty && !hasIndicateProperty) return; - foreach (const QLowEnergyServicePrivate::DescData &desc, charData.descriptorList) { + for (const QLowEnergyServicePrivate::DescData &desc : qAsConst(charData.descriptorList)) { if (desc.uuid != QBluetoothUuid::ClientCharacteristicConfiguration) continue; @@ -2925,7 +2925,7 @@ void QLowEnergyControllerPrivateBluez::handleExecuteWriteRequest(const QByteArra QVector<QLowEnergyCharacteristic> characteristics; QVector<QLowEnergyDescriptor> descriptors; if (!cancel) { - foreach (const WriteRequest &request, requests) { + for (const WriteRequest &request : qAsConst(requests)) { Attribute &attribute = localAttributes[request.handle]; if (request.valueOffset > attribute.value.count()) { sendErrorResponse(packet.at(0), request.handle, ATT_ERROR_INVALID_OFFSET); @@ -2952,9 +2952,9 @@ void QLowEnergyControllerPrivateBluez::handleExecuteWriteRequest(const QByteArra sendPacket(QByteArray(1, ATT_OP_EXECUTE_WRITE_RESPONSE)); - foreach (const QLowEnergyCharacteristic &characteristic, characteristics) + for (const QLowEnergyCharacteristic &characteristic : qAsConst(characteristics)) emit characteristic.d_ptr->characteristicChanged(characteristic, characteristic.value()); - foreach (const QLowEnergyDescriptor &descriptor, descriptors) + for (const QLowEnergyDescriptor &descriptor : qAsConst(descriptors)) emit descriptor.d_ptr->descriptorWritten(descriptor, descriptor.value()); } @@ -3153,7 +3153,7 @@ bool QLowEnergyControllerPrivateBluez::isBonded() const QVector<QLowEnergyControllerPrivateBluez::TempClientConfigurationData> QLowEnergyControllerPrivateBluez::gatherClientConfigData() { QVector<TempClientConfigurationData> data; - foreach (const auto &service, localServices) { + for (const auto &service : qAsConst(localServices)) { for (auto charIt = service->characteristicList.begin(); charIt != service->characteristicList.end(); ++charIt) { QLowEnergyServicePrivate::CharData &charData = charIt.value(); @@ -3179,7 +3179,7 @@ void QLowEnergyControllerPrivateBluez::storeClientConfigurations() } QVector<ClientConfigurationData> clientConfigs; const QVector<TempClientConfigurationData> &tempConfigList = gatherClientConfigData(); - foreach (const auto &tempConfigData, tempConfigList) { + for (const auto &tempConfigData : tempConfigList) { Q_ASSERT(tempConfigData.descData->value.count() == 2); const quint16 value = bt_get_le16(tempConfigData.descData->value.constData()); if (value != 0) { @@ -3196,9 +3196,9 @@ void QLowEnergyControllerPrivateBluez::restoreClientConfigurations() const QVector<ClientConfigurationData> &restoredClientConfigs = isBonded() ? clientConfigData.value(remoteDevice.toUInt64()) : QVector<ClientConfigurationData>(); QVector<QLowEnergyHandle> notifications; - foreach (const auto &tempConfigData, tempConfigList) { + for (const auto &tempConfigData : tempConfigList) { bool wasRestored = false; - foreach (const auto &restoredData, restoredClientConfigs) { + for (const auto &restoredData : restoredClientConfigs) { if (restoredData.charValueHandle == tempConfigData.charValueHandle) { Q_ASSERT(tempConfigData.descData->value.count() == 2); putBtData(restoredData.configValue, tempConfigData.descData->value.data()); @@ -3219,7 +3219,7 @@ void QLowEnergyControllerPrivateBluez::restoreClientConfigurations() localAttributes[tempConfigData.configHandle].value = tempConfigData.descData->value; } - foreach (const QLowEnergyHandle handle, notifications) + for (const QLowEnergyHandle handle : qAsConst(notifications)) sendNotification(handle); sendNextIndication(); } @@ -3318,7 +3318,8 @@ void QLowEnergyControllerPrivateBluez::addToGenericAttributeList(const QLowEnerg serviceAttribute.properties = QLowEnergyCharacteristic::Read; serviceAttribute.value = uuidToByteArray(service.uuid()); QLowEnergyHandle currentHandle = startHandle; - foreach (const QLowEnergyService * const service, service.includedServices()) { + const QList<QLowEnergyService *> includedServices = service.includedServices(); + for (const QLowEnergyService * const service : includedServices) { Attribute attribute; attribute.handle = ++currentHandle; attribute.type = QBluetoothUuid(GATT_INCLUDED_SERVICE); @@ -3332,7 +3333,8 @@ void QLowEnergyControllerPrivateBluez::addToGenericAttributeList(const QLowEnerg putDataAndIncrement(service->serviceUuid(), valueData); localAttributes[attribute.handle] = attribute; } - foreach (const QLowEnergyCharacteristicData &cd, service.characteristics()) { + const QList<QLowEnergyCharacteristicData> characteristics = service.characteristics(); + for (const QLowEnergyCharacteristicData &cd : characteristics) { Attribute attribute; // Characteristic declaration; @@ -3359,7 +3361,8 @@ void QLowEnergyControllerPrivateBluez::addToGenericAttributeList(const QLowEnerg attribute.maxLength = cd.maximumValueLength(); localAttributes[attribute.handle] = attribute; - foreach (const QLowEnergyDescriptorData &dd, cd.descriptors()) { + const QList<QLowEnergyDescriptorData> descriptors = cd.descriptors(); + for (const QLowEnergyDescriptorData &dd : descriptors) { attribute.handle = ++currentHandle; attribute.groupEndHandle = attribute.handle; attribute.type = dd.uuid(); diff --git a/src/bluetooth/qlowenergycontroller_osx.mm b/src/bluetooth/qlowenergycontroller_osx.mm index 2958e6ed..46782a22 100644 --- a/src/bluetooth/qlowenergycontroller_osx.mm +++ b/src/bluetooth/qlowenergycontroller_osx.mm @@ -880,7 +880,9 @@ quint16 QLowEnergyControllerPrivateOSX::updateValueOfDescriptor(QLowEnergyHandle QSharedPointer<QLowEnergyServicePrivate> QLowEnergyControllerPrivateOSX::serviceForHandle(QLowEnergyHandle handle) { - foreach (QSharedPointer<QLowEnergyServicePrivate> service, discoveredServices.values()) { + const QList<QSharedPointer<QLowEnergyServicePrivate>> services + = discoveredServices.values(); + for (QSharedPointer<QLowEnergyServicePrivate> service : services) { if (service->startHandle <= handle && handle <= service->endHandle) return service; } @@ -963,7 +965,9 @@ void QLowEnergyControllerPrivateOSX::setErrorDescription(QLowEnergyController::E void QLowEnergyControllerPrivateOSX::invalidateServices() { - foreach (const QSharedPointer<QLowEnergyServicePrivate> service, discoveredServices.values()) { + const QList<QSharedPointer<QLowEnergyServicePrivate>> services + = discoveredServices.values(); + for (const QSharedPointer<QLowEnergyServicePrivate> service : services) { service->setController(nullptr); service->setState(QLowEnergyService::InvalidService); } diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp index 917f3790..f6cca42c 100644 --- a/src/bluetooth/qlowenergycontroller_winrt.cpp +++ b/src/bluetooth/qlowenergycontroller_winrt.cpp @@ -292,7 +292,7 @@ QLowEnergyControllerPrivateWinRT::~QLowEnergyControllerPrivateWinRT() mDevice->remove_ConnectionStatusChanged(mStatusChangedToken); qCDebug(QT_BT_WINRT) << "Unregistering " << mValueChangedTokens.count() << " value change tokens"; - for (const ValueChangedEntry &entry : mValueChangedTokens) + for (const ValueChangedEntry &entry : qAsConst(mValueChangedTokens)) entry.characteristic->remove_ValueChanged(entry.token); } @@ -469,7 +469,7 @@ void QLowEnergyControllerPrivateWinRT::registerForValueChanges(const QBluetoothU { qCDebug(QT_BT_WINRT) << "Registering characteristic" << charUuid << "in service" << serviceUuid << "for value changes"; - for (const ValueChangedEntry &entry : mValueChangedTokens) { + for (const ValueChangedEntry &entry : qAsConst(mValueChangedTokens)) { GUID guuid; HRESULT hr; hr = entry.characteristic->get_Uuid(&guuid); @@ -662,7 +662,7 @@ void QLowEnergyControllerPrivateWinRT::discoverServiceDetails(const QBluetoothUu HRESULT hr; hr = QEventDispatcherWinRT::runOnXamlThread([indicateChars, service, this]() { - for (const QBluetoothUuid &indicateChar : indicateChars) + for (const QBluetoothUuid &indicateChar : qAsConst(indicateChars)) registerForValueChanges(service, indicateChar); return S_OK; }); diff --git a/src/bluetooth/qlowenergycontrollerbase.cpp b/src/bluetooth/qlowenergycontrollerbase.cpp index c7b9ec0b..8b4c2c10 100644 --- a/src/bluetooth/qlowenergycontrollerbase.cpp +++ b/src/bluetooth/qlowenergycontrollerbase.cpp @@ -70,7 +70,7 @@ bool QLowEnergyControllerPrivate::isValidLocalAdapter() const QList<QBluetoothHostInfo> foundAdapters = QBluetoothLocalDevice::allDevices(); bool adapterFound = false; - foreach (const QBluetoothHostInfo &info, foundAdapters) { + for (const QBluetoothHostInfo &info : foundAdapters) { if (info.address() == localAdapter) { adapterFound = true; break; @@ -255,7 +255,7 @@ quint16 QLowEnergyControllerPrivate::updateValueOfDescriptor( void QLowEnergyControllerPrivate::invalidateServices() { - foreach (const QSharedPointer<QLowEnergyServicePrivate> service, serviceList.values()) { + for (QSharedPointer<QLowEnergyServicePrivate> service : serviceList.values()) { service->setController(0); service->setState(QLowEnergyService::InvalidService); } @@ -278,7 +278,8 @@ QLowEnergyService *QLowEnergyControllerPrivate::addServiceHelper( servicePrivate->uuid = service.uuid(); servicePrivate->type = service.type() == QLowEnergyServiceData::ServiceTypePrimary ? QLowEnergyService::PrimaryService : QLowEnergyService::IncludedService; - foreach (QLowEnergyService * const includedService, service.includedServices()) { + const QList<QLowEnergyService *> includedServices = service.includedServices(); + for (QLowEnergyService * const includedService : includedServices) { servicePrivate->includedServices << includedService->serviceUuid(); includedService->d_ptr->type |= QLowEnergyService::IncludedService; } @@ -287,14 +288,16 @@ QLowEnergyService *QLowEnergyControllerPrivate::addServiceHelper( const QLowEnergyHandle oldLastHandle = this->lastLocalHandle; servicePrivate->startHandle = ++this->lastLocalHandle; // Service declaration. this->lastLocalHandle += servicePrivate->includedServices.count(); // Include declarations. - foreach (const QLowEnergyCharacteristicData &cd, service.characteristics()) { + const QList<QLowEnergyCharacteristicData> characteristics = service.characteristics(); + for (const QLowEnergyCharacteristicData &cd : characteristics) { const QLowEnergyHandle declHandle = ++this->lastLocalHandle; QLowEnergyServicePrivate::CharData charData; charData.valueHandle = ++this->lastLocalHandle; charData.uuid = cd.uuid(); charData.properties = cd.properties(); charData.value = cd.value(); - foreach (const QLowEnergyDescriptorData &dd, cd.descriptors()) { + const QList<QLowEnergyDescriptorData> descriptors = cd.descriptors(); + for (const QLowEnergyDescriptorData &dd : descriptors) { QLowEnergyServicePrivate::DescData descData; descData.uuid = dd.uuid(); descData.value = dd.value(); diff --git a/src/bluetooth/qlowenergyservice.cpp b/src/bluetooth/qlowenergyservice.cpp index 357d3901..1529d3c2 100644 --- a/src/bluetooth/qlowenergyservice.cpp +++ b/src/bluetooth/qlowenergyservice.cpp @@ -510,7 +510,7 @@ QList<QLowEnergyCharacteristic> QLowEnergyService::characteristics() const QList<QLowEnergyHandle> handles = d_ptr->characteristicList.keys(); std::sort(handles.begin(), handles.end()); - foreach (const QLowEnergyHandle &handle, handles) { + for (const QLowEnergyHandle &handle : qAsConst(handles)) { QLowEnergyCharacteristic characteristic(d_ptr, handle); results.append(characteristic); } diff --git a/src/bluetooth/qlowenergyservice_osx.mm b/src/bluetooth/qlowenergyservice_osx.mm index 4423887a..c294b693 100644 --- a/src/bluetooth/qlowenergyservice_osx.mm +++ b/src/bluetooth/qlowenergyservice_osx.mm @@ -129,7 +129,7 @@ QList<QLowEnergyCharacteristic> QLowEnergyService::characteristics() const std::sort(handles.begin(), handles.end()); - foreach (const QLowEnergyHandle &handle, handles) { + for (const QLowEnergyHandle &handle : qAsConst(handles)) { QLowEnergyCharacteristic characteristic(d_ptr, handle); result.append(characteristic); } diff --git a/src/bluetooth/qlowenergyservicedata.cpp b/src/bluetooth/qlowenergyservicedata.cpp index f40addd2..c536da14 100644 --- a/src/bluetooth/qlowenergyservicedata.cpp +++ b/src/bluetooth/qlowenergyservicedata.cpp @@ -170,7 +170,7 @@ QList<QLowEnergyCharacteristicData> QLowEnergyServiceData::characteristics() con void QLowEnergyServiceData::setCharacteristics(const QList<QLowEnergyCharacteristicData> &characteristics) { d->characteristics.clear(); - foreach (const QLowEnergyCharacteristicData &cd, characteristics) + for (const QLowEnergyCharacteristicData &cd : characteristics) addCharacteristic(cd); } diff --git a/src/imports/nfc/qdeclarativenearfield.cpp b/src/imports/nfc/qdeclarativenearfield.cpp index a9528462..c6c53ba4 100644 --- a/src/imports/nfc/qdeclarativenearfield.cpp +++ b/src/imports/nfc/qdeclarativenearfield.cpp @@ -211,7 +211,7 @@ void QDeclarativeNearField::registerMessageHandler() QNdefFilter ndefFilter; ndefFilter.setOrderMatch(m_orderMatch); - foreach (const QDeclarativeNdefFilter *filter, m_filterList) { + for (const QDeclarativeNdefFilter *filter : qAsConst(m_filterList)) { const QString type = filter->type(); uint min = filter->minimum() < 0 ? UINT_MAX : filter->minimum(); uint max = filter->maximum() < 0 ? UINT_MAX : filter->maximum(); @@ -236,7 +236,7 @@ void QDeclarativeNearField::_q_handleNdefMessage(const QNdefMessage &message) listRef.clear(); - foreach (const QNdefRecord &record, message) + for (const QNdefRecord &record : message) listRef.append(qNewDeclarativeNdefRecordForNdefRecord(record)); m_messageUpdating = false; diff --git a/src/nfc/android/androidmainnewintentlistener.cpp b/src/nfc/android/androidmainnewintentlistener.cpp index 09738cb8..2076453d 100644 --- a/src/nfc/android/androidmainnewintentlistener.cpp +++ b/src/nfc/android/androidmainnewintentlistener.cpp @@ -61,7 +61,7 @@ MainNfcNewIntentListener::~MainNfcNewIntentListener() bool MainNfcNewIntentListener::handleNewIntent(JNIEnv */*env*/, jobject intent) { listenersLock.lockForRead(); - foreach (AndroidNfc::AndroidNfcListenerInterface *listener, listeners) { + for (AndroidNfc::AndroidNfcListenerInterface *listener : qAsConst(listeners)) { listener->newIntent(QAndroidJniObject(intent)); } listenersLock.unlock(); diff --git a/src/nfc/neard/neard_helper.cpp b/src/nfc/neard/neard_helper.cpp index 9922c1a8..90781a5b 100644 --- a/src/nfc/neard/neard_helper.cpp +++ b/src/nfc/neard/neard_helper.cpp @@ -80,7 +80,8 @@ OrgFreedesktopDBusObjectManagerInterface *NeardHelper::dbusObjectManager() void NeardHelper::interfacesAdded(const QDBusObjectPath &path, InterfaceList interfaceList) { - foreach (const QString &key, interfaceList.keys()) { + const QList<QString> keys = interfaceList.keys(); + for (const QString &key : keys) { if (key == QStringLiteral("org.neard.Tag")) { emit tagFound(path); break; diff --git a/src/nfc/nfc.pro b/src/nfc/nfc.pro index ae65640a..ed88b79a 100644 --- a/src/nfc/nfc.pro +++ b/src/nfc/nfc.pro @@ -1,5 +1,6 @@ TARGET = QtNfc QT = core +DEFINES += QT_NO_FOREACH QMAKE_DOCS = $$PWD/doc/qtnfc.qdocconf OTHER_FILES += doc/src/*.qdoc # show .qdoc files in Qt Creator diff --git a/src/nfc/qllcpsocket_android_p.cpp b/src/nfc/qllcpsocket_android_p.cpp index 26b50c34..97b8db16 100644 --- a/src/nfc/qllcpsocket_android_p.cpp +++ b/src/nfc/qllcpsocket_android_p.cpp @@ -208,7 +208,7 @@ qint64 QLlcpSocketPrivate::writeData(const char *data, qint64 len) qint64 QLlcpSocketPrivate::bytesAvailable() const { /*qint64 available = 0; - foreach (const QByteArray &datagram, m_receivedDatagrams) + for (const QByteArray &datagram : qAsConst(m_receivedDatagrams)) available += datagram.length(); return available;*/ @@ -217,7 +217,7 @@ qint64 QLlcpSocketPrivate::bytesAvailable() const bool QLlcpSocketPrivate::canReadLine() const { - /*foreach (const QByteArray &datagram, m_receivedDatagrams) { + /*for (const QByteArray &datagram : qAsConst(m_receivedDatagrams)) { if (datagram.contains('\n')) return true; }*/ diff --git a/src/nfc/qnearfieldmanager_android.cpp b/src/nfc/qnearfieldmanager_android.cpp index 297f8ef8..0b305501 100644 --- a/src/nfc/qnearfieldmanager_android.cpp +++ b/src/nfc/qnearfieldmanager_android.cpp @@ -65,7 +65,7 @@ extern "C" { QNearFieldManager::AdapterState adapterState = static_cast<QNearFieldManager::AdapterState>((int) state); - for (const auto listener : *broadcastListener) { + for (const auto listener : qAsConst(*broadcastListener)) { Q_EMIT listener->adapterStateChanged(adapterState); } } @@ -153,7 +153,7 @@ void QNearFieldManagerPrivateImpl::handlerNdefMessageRead(const QNdefMessage &me filterRecords.append(vr); } - foreach (const QNdefRecord &record, message) { + for (const QNdefRecord &record : message) { for (int j = 0; matched && (j < filterRecords.count()); ++j) { VerifyRecord &vr = filterRecords[j]; diff --git a/src/nfc/qnearfieldmanager_neard.cpp b/src/nfc/qnearfieldmanager_neard.cpp index 7c1c6e05..4df1e0ef 100644 --- a/src/nfc/qnearfieldmanager_neard.cpp +++ b/src/nfc/qnearfieldmanager_neard.cpp @@ -62,9 +62,11 @@ QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl() } bool found = false; - foreach (const QDBusObjectPath &path, reply.value().keys()) { + const QList<QDBusObjectPath> paths = reply.value().keys(); + for (const QDBusObjectPath &path : paths) { const InterfaceList ifaceList = reply.value().value(path); - foreach (const QString &iface, ifaceList.keys()) { + const QStringList ifaces = ifaceList.keys(); + for (const QString &iface : ifaces) { if (iface == QStringLiteral("org.neard.Adapter")) { found = true; m_adapterPath = path.path(); @@ -106,7 +108,8 @@ bool QNearFieldManagerPrivateImpl::isAvailable() const return false; } - foreach (const QDBusObjectPath &path, reply.value().keys()) { + const QList<QDBusObjectPath> paths = reply.value().keys(); + for (const QDBusObjectPath &path : paths) { if (m_adapterPath == path.path()) return true; } diff --git a/src/nfc/qnearfieldmanagervirtualbase.cpp b/src/nfc/qnearfieldmanagervirtualbase.cpp index 3fd97508..82e272ce 100644 --- a/src/nfc/qnearfieldmanagervirtualbase.cpp +++ b/src/nfc/qnearfieldmanagervirtualbase.cpp @@ -173,7 +173,7 @@ void QNearFieldManagerPrivateVirtualBase::ndefReceived(const QNdefMessage &messa filterRecords.append(vr); } - foreach (const QNdefRecord &record, message) { + for (const QNdefRecord &record : message) { for (int j = 0; matched && (j < filterRecords.count()); ++j) { VerifyRecord &vr = filterRecords[j]; diff --git a/src/nfc/qnearfieldtagtype1.cpp b/src/nfc/qnearfieldtagtype1.cpp index 7f27fbe9..b3479203 100644 --- a/src/nfc/qnearfieldtagtype1.cpp +++ b/src/nfc/qnearfieldtagtype1.cpp @@ -279,11 +279,11 @@ void QNearFieldTagType1Private::progressToNextNdefWriteMessageState() m_tlvWriter = new QTlvWriter(q); // write old TLVs - foreach (const Tlv &tlv, m_tlvs) + for (const Tlv &tlv : qAsConst(m_tlvs)) m_tlvWriter->writeTlv(tlv.first, tlv.second); // write new NDEF message TLVs - foreach (const QNdefMessage &message, m_ndefWriteMessages) + for (const QNdefMessage &message : qAsConst(m_ndefWriteMessages)) m_tlvWriter->writeTlv(0x03, message.toByteArray()); // write terminator TLV diff --git a/src/nfc/qnearfieldtarget_neard_p.h b/src/nfc/qnearfieldtarget_neard_p.h index 625cee67..9844d99e 100644 --- a/src/nfc/qnearfieldtarget_neard_p.h +++ b/src/nfc/qnearfieldtarget_neard_p.h @@ -348,7 +348,7 @@ private: if (m_readRequested) { qCDebug(QT_NFC_NEARD) << "creating Ndef message, reading" << m_recordPaths.length() << "record paths"; QNdefMessage newNdefMessage; - foreach (const QDBusObjectPath &recordPath, m_recordPaths) + for (const QDBusObjectPath &recordPath : qAsConst(m_recordPaths)) newNdefMessage.append(readRecord(recordPath)); if (!newNdefMessage.isEmpty()) { diff --git a/src/nfc/qtlv.cpp b/src/nfc/qtlv.cpp index 7aa87ac0..3168854c 100644 --- a/src/nfc/qtlv.cpp +++ b/src/nfc/qtlv.cpp @@ -284,7 +284,8 @@ bool QTlvReader::readMoreData(int sparseOffset) int QTlvReader::absoluteOffset(int sparseOffset) const { int absoluteOffset = sparseOffset; - foreach (int offset, m_reservedMemory.keys()) { + const QList<int> offsets = m_reservedMemory.keys(); + for (const int offset : offsets) { if (offset <= absoluteOffset) absoluteOffset += m_reservedMemory.value(offset); } @@ -298,7 +299,8 @@ int QTlvReader::absoluteOffset(int sparseOffset) const */ int QTlvReader::dataLength(int startOffset) const { - foreach (int offset, m_reservedMemory.keys()) { + const QList<int> offsets = m_reservedMemory.keys(); + for (const int offset : offsets) { if (offset <= startOffset) continue; 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(); |