summaryrefslogtreecommitdiffstats
path: root/examples/network
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2019-04-16 16:32:08 +0200
committerTobias Hunger <tobias.hunger@qt.io>2019-04-16 16:32:08 +0200
commit6630937e63ae5797487b86743a7733c8ae5cc42c (patch)
tree3d53dacf6430f9099e1fb20835881205de674961 /examples/network
parent37ed6dae00640f9cc980ffda05347c12a7eb5d7e (diff)
parentc7af193d2e49e9f10b86262e63d8d13abf72b5cf (diff)
Merge commit 'dev' into 'wip/cmake-merge'
Diffstat (limited to 'examples/network')
-rw-r--r--examples/network/bearermonitor/bearermonitor.cpp6
-rw-r--r--examples/network/dnslookup/dnslookup.cpp24
-rw-r--r--examples/network/dnslookup/dnslookup.pro3
-rw-r--r--examples/network/download/download.pro3
-rw-r--r--examples/network/downloadmanager/downloadmanager.pro3
-rw-r--r--examples/network/googlesuggest/googlesuggest.cpp2
-rw-r--r--examples/network/http/httpwindow.cpp2
-rw-r--r--examples/network/loopback/dialog.cpp6
-rw-r--r--examples/network/network-chat/client.cpp7
-rw-r--r--examples/network/network-chat/peermanager.cpp12
-rw-r--r--examples/network/network-chat/peermanager.h2
-rw-r--r--examples/network/securesocketclient/sslclient.cpp3
-rw-r--r--examples/network/torrent/addtorrentdialog.cpp3
-rw-r--r--examples/network/torrent/filemanager.cpp7
-rw-r--r--examples/network/torrent/mainwindow.cpp8
-rw-r--r--examples/network/torrent/metainfo.cpp8
-rw-r--r--examples/network/torrent/ratecontroller.cpp4
-rw-r--r--examples/network/torrent/torrentclient.cpp42
-rw-r--r--examples/network/torrent/torrentserver.cpp2
19 files changed, 79 insertions, 68 deletions
diff --git a/examples/network/bearermonitor/bearermonitor.cpp b/examples/network/bearermonitor/bearermonitor.cpp
index f9b899b06b..1a54f5ec8a 100644
--- a/examples/network/bearermonitor/bearermonitor.cpp
+++ b/examples/network/bearermonitor/bearermonitor.cpp
@@ -142,7 +142,8 @@ void BearerMonitor::configurationAdded(const QNetworkConfiguration &config, QTre
treeWidget->addTopLevelItem(item);
if (config.type() == QNetworkConfiguration::ServiceNetwork) {
- foreach (const QNetworkConfiguration &child, config.children())
+ const QList<QNetworkConfiguration> children = config.children();
+ for (const QNetworkConfiguration &child : children)
configurationAdded(child, item);
}
}
@@ -181,7 +182,8 @@ void BearerMonitor::configurationChanged(const QNetworkConfiguration &config)
void BearerMonitor::updateSnapConfiguration(QTreeWidgetItem *parent, const QNetworkConfiguration &snap)
{
QMap<QString, QTreeWidgetItem *> itemMap;
- foreach (QTreeWidgetItem *item, parent->takeChildren())
+ const QList<QTreeWidgetItem *> children = parent->takeChildren();
+ for (QTreeWidgetItem *item : children)
itemMap.insert(item->data(0, Qt::UserRole).toString(), item);
QList<QNetworkConfiguration> allConfigurations = snap.children();
diff --git a/examples/network/dnslookup/dnslookup.cpp b/examples/network/dnslookup/dnslookup.cpp
index 63819b170c..a2d927d43d 100644
--- a/examples/network/dnslookup/dnslookup.cpp
+++ b/examples/network/dnslookup/dnslookup.cpp
@@ -172,35 +172,43 @@ void DnsManager::showResults()
printf("Error: %i (%s)\n", dns->error(), qPrintable(dns->errorString()));
// CNAME records
- foreach (const QDnsDomainNameRecord &record, dns->canonicalNameRecords())
+ const QList<QDnsDomainNameRecord> cnameRecords = dns->canonicalNameRecords();
+ for (const QDnsDomainNameRecord &record : cnameRecords)
printf("%s\t%i\tIN\tCNAME\t%s\n", qPrintable(record.name()), record.timeToLive(), qPrintable(record.value()));
// A and AAAA records
- foreach (const QDnsHostAddressRecord &record, dns->hostAddressRecords()) {
+ const QList<QDnsHostAddressRecord> aRecords = dns->hostAddressRecords();
+ for (const QDnsHostAddressRecord &record : aRecords) {
const char *type = (record.value().protocol() == QAbstractSocket::IPv6Protocol) ? "AAAA" : "A";
printf("%s\t%i\tIN\t%s\t%s\n", qPrintable(record.name()), record.timeToLive(), type, qPrintable(record.value().toString()));
}
// MX records
- foreach (const QDnsMailExchangeRecord &record, dns->mailExchangeRecords())
+ const QList<QDnsMailExchangeRecord> mxRecords = dns->mailExchangeRecords();
+ for (const QDnsMailExchangeRecord &record : mxRecords)
printf("%s\t%i\tIN\tMX\t%u %s\n", qPrintable(record.name()), record.timeToLive(), record.preference(), qPrintable(record.exchange()));
// NS records
- foreach (const QDnsDomainNameRecord &record, dns->nameServerRecords())
+ const QList<QDnsDomainNameRecord> nsRecords = dns->nameServerRecords();
+ for (const QDnsDomainNameRecord &record : nsRecords)
printf("%s\t%i\tIN\tNS\t%s\n", qPrintable(record.name()), record.timeToLive(), qPrintable(record.value()));
// PTR records
- foreach (const QDnsDomainNameRecord &record, dns->pointerRecords())
+ const QList<QDnsDomainNameRecord> ptrRecords = dns->pointerRecords();
+ for (const QDnsDomainNameRecord &record : ptrRecords)
printf("%s\t%i\tIN\tPTR\t%s\n", qPrintable(record.name()), record.timeToLive(), qPrintable(record.value()));
// SRV records
- foreach (const QDnsServiceRecord &record, dns->serviceRecords())
+ const QList<QDnsServiceRecord> srvRecords = dns->serviceRecords();
+ for (const QDnsServiceRecord &record : srvRecords)
printf("%s\t%i\tIN\tSRV\t%u %u %u %s\n", qPrintable(record.name()), record.timeToLive(), record.priority(), record.weight(), record.port(), qPrintable(record.target()));
// TXT records
- foreach (const QDnsTextRecord &record, dns->textRecords()) {
+ const QList<QDnsTextRecord> txtRecords = dns->textRecords();
+ for (const QDnsTextRecord &record : txtRecords) {
QStringList values;
- foreach (const QByteArray &ba, record.values())
+ const QList<QByteArray> dnsRecords = record.values();
+ for (const QByteArray &ba : dnsRecords)
values << "\"" + QString::fromLatin1(ba) + "\"";
printf("%s\t%i\tIN\tTXT\t%s\n", qPrintable(record.name()), record.timeToLive(), qPrintable(values.join(' ')));
}
diff --git a/examples/network/dnslookup/dnslookup.pro b/examples/network/dnslookup/dnslookup.pro
index 0c6b512d3b..c72301420c 100644
--- a/examples/network/dnslookup/dnslookup.pro
+++ b/examples/network/dnslookup/dnslookup.pro
@@ -1,7 +1,6 @@
TEMPLATE = app
QT = core network
-mac:CONFIG -= app_bundle
-win32:CONFIG += console
+CONFIG += cmdline
HEADERS += dnslookup.h
SOURCES += dnslookup.cpp
diff --git a/examples/network/download/download.pro b/examples/network/download/download.pro
index 2c784c4197..63d80a0e7c 100644
--- a/examples/network/download/download.pro
+++ b/examples/network/download/download.pro
@@ -1,6 +1,5 @@
QT = core network
-CONFIG += console
-CONFIG -= app_bundle
+CONFIG += cmdline
SOURCES += main.cpp
diff --git a/examples/network/downloadmanager/downloadmanager.pro b/examples/network/downloadmanager/downloadmanager.pro
index 68972610fa..cd1a977e5d 100644
--- a/examples/network/downloadmanager/downloadmanager.pro
+++ b/examples/network/downloadmanager/downloadmanager.pro
@@ -1,6 +1,5 @@
QT = core network
-CONFIG += console
-CONFIG -= app_bundle
+CONFIG += cmdline
HEADERS += downloadmanager.h textprogressbar.h
SOURCES += downloadmanager.cpp main.cpp textprogressbar.cpp
diff --git a/examples/network/googlesuggest/googlesuggest.cpp b/examples/network/googlesuggest/googlesuggest.cpp
index 24fdde0a5c..d27beafd1e 100644
--- a/examples/network/googlesuggest/googlesuggest.cpp
+++ b/examples/network/googlesuggest/googlesuggest.cpp
@@ -160,7 +160,7 @@ void GSuggestCompletion::showCompletion(const QVector<QString> &choices)
for (const auto &choice : choices) {
auto item = new QTreeWidgetItem(popup);
item->setText(0, choice);
- item->setTextColor(0, color);
+ item->setForeground(0, color);
}
popup->setCurrentItem(popup->topLevelItem(0));
diff --git a/examples/network/http/httpwindow.cpp b/examples/network/http/httpwindow.cpp
index ec90b8f7fe..39ffb3cc87 100644
--- a/examples/network/http/httpwindow.cpp
+++ b/examples/network/http/httpwindow.cpp
@@ -319,7 +319,7 @@ void HttpWindow::slotAuthenticationRequired(QNetworkReply *, QAuthenticator *aut
void HttpWindow::sslErrors(QNetworkReply *, const QList<QSslError> &errors)
{
QString errorString;
- foreach (const QSslError &error, errors) {
+ for (const QSslError &error : errors) {
if (!errorString.isEmpty())
errorString += '\n';
errorString += error.errorString();
diff --git a/examples/network/loopback/dialog.cpp b/examples/network/loopback/dialog.cpp
index b4e6b0fd5e..d87f024031 100644
--- a/examples/network/loopback/dialog.cpp
+++ b/examples/network/loopback/dialog.cpp
@@ -99,7 +99,7 @@ void Dialog::start()
startButton->setEnabled(false);
#ifndef QT_NO_CURSOR
- QApplication::setOverrideCursor(Qt::WaitCursor);
+ QGuiApplication::setOverrideCursor(Qt::WaitCursor);
#endif
bytesWritten = 0;
@@ -162,7 +162,7 @@ void Dialog::updateServerProgress()
tcpServerConnection->close();
startButton->setEnabled(true);
#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
#endif
}
}
@@ -198,6 +198,6 @@ void Dialog::displayError(QAbstractSocket::SocketError socketError)
serverStatusLabel->setText(tr("Server ready"));
startButton->setEnabled(true);
#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
#endif
}
diff --git a/examples/network/network-chat/client.cpp b/examples/network/network-chat/client.cpp
index 97c2c44b6b..b76ef18238 100644
--- a/examples/network/network-chat/client.cpp
+++ b/examples/network/network-chat/client.cpp
@@ -71,8 +71,7 @@ void Client::sendMessage(const QString &message)
if (message.isEmpty())
return;
- QList<Connection *> connections = peers.values();
- foreach (Connection *connection, connections)
+ for (Connection *connection : qAsConst(peers))
connection->sendMessage(message);
}
@@ -90,8 +89,8 @@ bool Client::hasConnection(const QHostAddress &senderIp, int senderPort) const
if (!peers.contains(senderIp))
return false;
- QList<Connection *> connections = peers.values(senderIp);
- foreach (Connection *connection, connections) {
+ const QList<Connection *> connections = peers.values(senderIp);
+ for (const Connection *connection : connections) {
if (connection->peerPort() == senderPort)
return true;
}
diff --git a/examples/network/network-chat/peermanager.cpp b/examples/network/network-chat/peermanager.cpp
index 38fa2e8e50..5c48edb1b9 100644
--- a/examples/network/network-chat/peermanager.cpp
+++ b/examples/network/network-chat/peermanager.cpp
@@ -104,9 +104,9 @@ void PeerManager::startBroadcasting()
broadcastTimer.start();
}
-bool PeerManager::isLocalHostAddress(const QHostAddress &address)
+bool PeerManager::isLocalHostAddress(const QHostAddress &address) const
{
- foreach (QHostAddress localAddress, ipAddresses) {
+ for (const QHostAddress &localAddress : ipAddresses) {
if (address.isEqual(localAddress))
return true;
}
@@ -125,7 +125,7 @@ void PeerManager::sendBroadcastDatagram()
}
bool validBroadcastAddresses = true;
- foreach (QHostAddress address, broadcastAddresses) {
+ for (const QHostAddress &address : qAsConst(broadcastAddresses)) {
if (broadcastSocket.writeDatagram(datagram, address,
broadcastPort) == -1)
validBroadcastAddresses = false;
@@ -182,8 +182,10 @@ void PeerManager::updateAddresses()
{
broadcastAddresses.clear();
ipAddresses.clear();
- foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) {
- foreach (QNetworkAddressEntry entry, interface.addressEntries()) {
+ const QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
+ for (const QNetworkInterface &interface : interfaces) {
+ const QList<QNetworkAddressEntry> entries = interface.addressEntries();
+ for (const QNetworkAddressEntry &entry : entries) {
QHostAddress broadcastAddress = entry.broadcast();
if (broadcastAddress != QHostAddress::Null && entry.ip() != QHostAddress::LocalHost) {
broadcastAddresses << broadcastAddress;
diff --git a/examples/network/network-chat/peermanager.h b/examples/network/network-chat/peermanager.h
index b79028235b..6105c83115 100644
--- a/examples/network/network-chat/peermanager.h
+++ b/examples/network/network-chat/peermanager.h
@@ -70,7 +70,7 @@ public:
void setServerPort(int port);
QString userName() const;
void startBroadcasting();
- bool isLocalHostAddress(const QHostAddress &address);
+ bool isLocalHostAddress(const QHostAddress &address) const;
signals:
void newConnection(Connection *connection);
diff --git a/examples/network/securesocketclient/sslclient.cpp b/examples/network/securesocketclient/sslclient.cpp
index afeec033ff..79ed7746d6 100644
--- a/examples/network/securesocketclient/sslclient.cpp
+++ b/examples/network/securesocketclient/sslclient.cpp
@@ -206,7 +206,8 @@ void SslClient::setupUi()
padLock->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored);
QHBoxLayout *layout = new QHBoxLayout(form->hostNameEdit);
- layout->setMargin(form->hostNameEdit->style()->pixelMetric(QStyle::PM_DefaultFrameWidth));
+ const int margin = form->hostNameEdit->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
+ layout->setContentsMargins(margin, margin, margin, margin);
layout->setSpacing(0);
layout->addStretch();
layout->addWidget(padLock);
diff --git a/examples/network/torrent/addtorrentdialog.cpp b/examples/network/torrent/addtorrentdialog.cpp
index 0d197ec5fa..c87110ac4a 100644
--- a/examples/network/torrent/addtorrentdialog.cpp
+++ b/examples/network/torrent/addtorrentdialog.cpp
@@ -148,7 +148,8 @@ void AddTorrentDialog::setTorrent(const QString &torrentFile)
ui.torrentContents->setHtml(metaInfo.singleFile().name);
} else {
QString html;
- foreach (MetaInfoMultiFile file, metaInfo.multiFiles()) {
+ const QList<MetaInfoMultiFile> multiFiles = metaInfo.multiFiles();
+ for (const MetaInfoMultiFile &file : multiFiles) {
QString name = metaInfo.name();
if (!name.isEmpty()) {
html += name;
diff --git a/examples/network/torrent/filemanager.cpp b/examples/network/torrent/filemanager.cpp
index d05408cebc..69345442c7 100644
--- a/examples/network/torrent/filemanager.cpp
+++ b/examples/network/torrent/filemanager.cpp
@@ -77,7 +77,7 @@ FileManager::~FileManager()
cond.wakeOne();
wait();
- foreach (QFile *file, files) {
+ for (QFile *file : qAsConst(files)) {
file->close();
delete file;
}
@@ -285,7 +285,8 @@ bool FileManager::generateFiles()
return false;
}
- foreach (const MetaInfoMultiFile &entry, metaInfo.multiFiles()) {
+ const QList<MetaInfoMultiFile> multiFiles = metaInfo.multiFiles();
+ for (const MetaInfoMultiFile &entry : multiFiles) {
QString filePath = QFileInfo(prefix + entry.path).path();
if (!QFile::exists(filePath)) {
if (!dir.mkpath(filePath)) {
@@ -437,7 +438,7 @@ void FileManager::verifyFileContents()
}
// Verify all pending pieces
- foreach (int index, newPendingVerificationRequests)
+ for (int index : qAsConst(newPendingVerificationRequests))
emit pieceVerified(index, verifySinglePiece(index));
}
diff --git a/examples/network/torrent/mainwindow.cpp b/examples/network/torrent/mainwindow.cpp
index 660472c05c..704012ef6d 100644
--- a/examples/network/torrent/mainwindow.cpp
+++ b/examples/network/torrent/mainwindow.cpp
@@ -239,7 +239,7 @@ int MainWindow::rowOfClient(TorrentClient *client) const
// Return the row that displays this client's status, or -1 if the
// client is not known.
int row = 0;
- foreach (Job job, jobs) {
+ for (const Job &job : jobs) {
if (job.client == client)
return row;
++row;
@@ -358,7 +358,7 @@ bool MainWindow::addTorrent(const QString &fileName, const QString &destinationF
const QByteArray &resumeState)
{
// Check if the torrent is already being downloaded.
- foreach (Job job, jobs) {
+ for (const Job &job : qAsConst(jobs)) {
if (job.torrentFileName == fileName && job.destinationDirectory == destinationFolder) {
QMessageBox::warning(this, tr("Already downloading"),
tr("The torrent file %1 is "
@@ -630,7 +630,7 @@ void MainWindow::about()
QPushButton *quitButton = new QPushButton("OK");
QHBoxLayout *topLayout = new QHBoxLayout;
- topLayout->setMargin(10);
+ topLayout->setContentsMargins(10, 10, 10, 10);
topLayout->setSpacing(10);
topLayout->addWidget(icon);
topLayout->addWidget(text);
@@ -684,7 +684,7 @@ void MainWindow::closeEvent(QCloseEvent *)
// them to signal that they have stopped.
jobsToStop = 0;
jobsStopped = 0;
- foreach (Job job, jobs) {
+ for (const Job &job : qAsConst(jobs)) {
++jobsToStop;
TorrentClient *client = job.client;
client->disconnect();
diff --git a/examples/network/torrent/metainfo.cpp b/examples/network/torrent/metainfo.cpp
index 565533e2f9..29b34b12a0 100644
--- a/examples/network/torrent/metainfo.cpp
+++ b/examples/network/torrent/metainfo.cpp
@@ -101,10 +101,10 @@ bool MetaInfo::parse(const QByteArray &data)
QList<QVariant> files = info.value("files").toList();
for (int i = 0; i < files.size(); ++i) {
- QMap<QByteArray, QVariant> file = qvariant_cast<Dictionary>(files.at(i));
- QList<QVariant> pathElements = file.value("path").toList();
+ const QMap<QByteArray, QVariant> file = qvariant_cast<Dictionary>(files.at(i));
+ const QList<QVariant> pathElements = file.value("path").toList();
QByteArray path;
- foreach (QVariant p, pathElements) {
+ for (const QVariant &p : pathElements) {
if (!path.isEmpty())
path += '/';
path += p.toByteArray();
@@ -221,7 +221,7 @@ qint64 MetaInfo::totalSize() const
return singleFile().length;
qint64 size = 0;
- foreach (MetaInfoMultiFile file, multiFiles())
+ for (const MetaInfoMultiFile &file : metaInfoMultiFiles)
size += file.length;
return size;
}
diff --git a/examples/network/torrent/ratecontroller.cpp b/examples/network/torrent/ratecontroller.cpp
index cec05c7455..47b49dba30 100644
--- a/examples/network/torrent/ratecontroller.cpp
+++ b/examples/network/torrent/ratecontroller.cpp
@@ -78,7 +78,7 @@ void RateController::removeSocket(PeerWireClient *socket)
void RateController::setDownloadLimit(int bytesPerSecond)
{
downLimit = bytesPerSecond;
- foreach (PeerWireClient *socket, sockets)
+ for (PeerWireClient *socket : qAsConst(sockets))
socket->setReadBufferSize(downLimit * 4);
}
@@ -108,7 +108,7 @@ void RateController::transfer()
}
QSet<PeerWireClient *> pendingSockets;
- foreach (PeerWireClient *client, sockets) {
+ for (PeerWireClient *client : qAsConst(sockets)) {
if (client->canTransferMore())
pendingSockets << client;
}
diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp
index 95232646ab..d01a5f3d9e 100644
--- a/examples/network/torrent/torrentclient.cpp
+++ b/examples/network/torrent/torrentclient.cpp
@@ -383,7 +383,7 @@ qint64 TorrentClient::uploadedBytes() const
int TorrentClient::connectedPeerCount() const
{
int tmp = 0;
- foreach (PeerWireClient *client, d->connections) {
+ for (PeerWireClient *client : d->connections) {
if (client->state() == QAbstractSocket::ConnectedState)
++tmp;
}
@@ -393,7 +393,7 @@ int TorrentClient::connectedPeerCount() const
int TorrentClient::seedCount() const
{
int tmp = 0;
- foreach (PeerWireClient *client, d->connections) {
+ for (PeerWireClient *client : d->connections) {
if (client->availablePieces().count(true) == d->pieceCount)
++tmp;
}
@@ -464,7 +464,7 @@ void TorrentClient::stop()
}
// Abort all existing connections
- foreach (PeerWireClient *client, d->connections) {
+ for (PeerWireClient *client : qAsConst(d->connections)) {
RateController::instance()->removeSocket(client);
ConnectionManager::instance()->removeConnection(client);
client->abort();
@@ -487,7 +487,7 @@ void TorrentClient::setPaused(bool paused)
// connections to 0. Keep the list of peers, so we can quickly
// resume later.
d->setState(Paused);
- foreach (PeerWireClient *client, d->connections)
+ for (PeerWireClient *client : qAsConst(d->connections))
client->abort();
d->connections.clear();
TorrentServer::instance()->removeClient(this);
@@ -622,7 +622,7 @@ void TorrentClient::pieceVerified(int pieceIndex, bool ok)
}
// Update the peer list so we know who's still interesting.
- foreach (TorrentPeer *peer, d->peers) {
+ for (TorrentPeer *peer : qAsConst(d->peers)) {
if (!peer->interesting)
continue;
bool interesting = false;
@@ -642,7 +642,7 @@ void TorrentClient::pieceVerified(int pieceIndex, bool ok)
d->incompletePieces.clearBit(pieceIndex);
// Notify connected peers.
- foreach (PeerWireClient *client, d->connections) {
+ for (PeerWireClient *client : qAsConst(d->connections)) {
if (client->state() == QAbstractSocket::ConnectedState
&& !client->availablePieces().testBit(pieceIndex)) {
client->sendPieceNotification(pieceIndex);
@@ -720,9 +720,9 @@ QList<TorrentPeer *> TorrentClient::weighedFreePeers() const
qint64 now = QDateTime::currentSecsSinceEpoch();
QList<TorrentPeer *> freePeers;
QMap<QString, int> connectionsPerPeer;
- foreach (TorrentPeer *peer, d->peers) {
+ for (TorrentPeer *peer : d->peers) {
bool busy = false;
- foreach (PeerWireClient *client, d->connections) {
+ for (PeerWireClient *client : d->connections) {
if (client->state() == PeerWireClient::ConnectedState
&& client->peerAddress() == peer->address
&& client->peerPort() == peer->port) {
@@ -742,7 +742,7 @@ QList<TorrentPeer *> TorrentClient::weighedFreePeers() const
// Assign points based on connection speed and pieces available.
QList<QPair<int, TorrentPeer *> > points;
- foreach (TorrentPeer *peer, freePeers) {
+ for (TorrentPeer *peer : qAsConst(freePeers)) {
int tmp = 0;
if (peer->interesting) {
tmp += peer->numCompletedPieces;
@@ -765,7 +765,7 @@ QList<TorrentPeer *> TorrentClient::weighedFreePeers() const
QMultiMap<int, TorrentPeer *> pointMap;
int lowestScore = 0;
int lastIndex = 0;
- foreach (PointPair point, points) {
+ for (const PointPair &point : qAsConst(points)) {
if (point.first > lowestScore) {
lowestScore = point.first;
++lastIndex;
@@ -816,7 +816,7 @@ void TorrentClient::setupOutgoingConnection()
PeerWireClient *client = qobject_cast<PeerWireClient *>(sender());
// Update connection statistics.
- foreach (TorrentPeer *peer, d->peers) {
+ for (TorrentPeer *peer : qAsConst(d->peers)) {
if (peer->port == client->peerPort() && peer->address == client->peerAddress()) {
peer->connectTime = peer->lastVisited - peer->connectStart;
break;
@@ -1085,7 +1085,7 @@ void TorrentClient::scheduleUploads()
// no use in unchoking them.
QList<PeerWireClient *> allClients = d->connections;
QMultiMap<int, PeerWireClient *> transferSpeeds;
- foreach (PeerWireClient *client, allClients) {
+ for (PeerWireClient *client : qAsConst(allClients)) {
if (client->state() == QAbstractSocket::ConnectedState
&& client->availablePieces().count(true) != d->pieceCount) {
if (d->state == Seeding) {
@@ -1143,7 +1143,7 @@ void TorrentClient::scheduleDownloads()
// Check what each client is doing, and assign payloads to those
// who are either idle or done.
- foreach (PeerWireClient *client, d->connections)
+ for (PeerWireClient *client : qAsConst(d->connections))
schedulePieceForClient(client);
}
@@ -1222,7 +1222,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
incompletePiecesAvailableToClient &= client->availablePieces();
// Remove all pieces that this client has already requested.
- foreach (int i, currentPieces)
+ for (int i : qAsConst(currentPieces))
incompletePiecesAvailableToClient.clearBit(i);
// Only continue if more pieces can be scheduled. If no pieces
@@ -1258,7 +1258,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
memset(occurrences, 0, d->pieceCount * sizeof(int));
// Count how many of each piece are available.
- foreach (PeerWireClient *peer, d->connections) {
+ for (PeerWireClient *peer : qAsConst(d->connections)) {
QBitArray peerPieces = peer->availablePieces();
int peerPiecesSize = peerPieces.size();
for (int i = 0; i < peerPiecesSize; ++i) {
@@ -1356,7 +1356,7 @@ void TorrentClient::requestMore(PeerWireClient *client)
// Starting with the first piece that we're waiting for, request
// blocks until the quota is filled up.
- foreach (TorrentPiece *piece, piecesInProgress) {
+ for (TorrentPiece *piece : qAsConst(piecesInProgress)) {
numBlocksInProgress += requestBlocks(client, piece, maxInProgress - numBlocksInProgress);
if (numBlocksInProgress == maxInProgress)
break;
@@ -1450,8 +1450,8 @@ void TorrentClient::peerUnchoked()
void TorrentClient::addToPeerList(const QList<TorrentPeer> &peerList)
{
// Add peers we don't already know of to our list of peers.
- QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
- foreach (TorrentPeer peer, peerList) {
+ const QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
+ for (const TorrentPeer &peer : peerList) {
if (addresses.contains(peer.address)
&& peer.port == TorrentServer::instance()->serverPort()) {
// Skip our own server.
@@ -1459,7 +1459,7 @@ void TorrentClient::addToPeerList(const QList<TorrentPeer> &peerList)
}
bool known = false;
- foreach (TorrentPeer *knownPeer, d->peers) {
+ for (const TorrentPeer *knownPeer : qAsConst(d->peers)) {
if (knownPeer->port == peer.port
&& knownPeer->address == peer.address) {
known = true;
@@ -1486,8 +1486,8 @@ void TorrentClient::addToPeerList(const QList<TorrentPeer> &peerList)
if (d->peers.size() > maxPeers) {
// Find what peers are currently connected & active
QSet<TorrentPeer *> activePeers;
- foreach (TorrentPeer *peer, d->peers) {
- foreach (PeerWireClient *client, d->connections) {
+ for (TorrentPeer *peer : qAsConst(d->peers)) {
+ for (const PeerWireClient *client : qAsConst(d->connections)) {
if (client->peer() == peer && (client->downloadSpeed() + client->uploadSpeed()) > 1024)
activePeers << peer;
}
diff --git a/examples/network/torrent/torrentserver.cpp b/examples/network/torrent/torrentserver.cpp
index da98529fe0..c68f33249c 100644
--- a/examples/network/torrent/torrentserver.cpp
+++ b/examples/network/torrent/torrentserver.cpp
@@ -102,7 +102,7 @@ void TorrentServer::removeClient()
void TorrentServer::processInfoHash(const QByteArray &infoHash)
{
PeerWireClient *peer = qobject_cast<PeerWireClient *>(sender());
- foreach (TorrentClient *client, clients) {
+ for (TorrentClient *client : qAsConst(clients)) {
if (client->state() >= TorrentClient::Searching && client->infoHash() == infoHash) {
peer->disconnect(peer, 0, this, 0);
client->setupIncomingConnection(peer);