From 77e708d1676803ce4ed7a2511fd80f8848522c63 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 23 May 2019 10:39:56 +0200 Subject: Torrent example: replace Java-style iteration with STL iterators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Java-iterators are going to be deprecated. Change-Id: I2e6353f3fd9e2ddaf0767e7f6cea713249d9591e Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Paul Wicking --- examples/network/torrent/ratecontroller.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/network/torrent/ratecontroller.cpp b/examples/network/torrent/ratecontroller.cpp index 47b49dba30..87c65096b6 100644 --- a/examples/network/torrent/ratecontroller.cpp +++ b/examples/network/torrent/ratecontroller.cpp @@ -123,11 +123,11 @@ void RateController::transfer() qint64 writeChunk = qMax(1, bytesToWrite / pendingSockets.size()); qint64 readChunk = qMax(1, bytesToRead / pendingSockets.size()); - QSetIterator it(pendingSockets); - while (it.hasNext() && (bytesToWrite > 0 || bytesToRead > 0)) { - PeerWireClient *socket = it.next(); + for (auto it = pendingSockets.begin(), end = pendingSockets.end(); it != end && (bytesToWrite > 0 || bytesToRead > 0); /*erasing*/) { + auto current = it++; + PeerWireClient *socket = *current; if (socket->state() != QAbstractSocket::ConnectedState) { - pendingSockets.remove(socket); + pendingSockets.erase(current); continue; } @@ -156,7 +156,7 @@ void RateController::transfer() if (dataTransferred && socket->canTransferMore()) canTransferMore = true; else - pendingSockets.remove(socket); + pendingSockets.erase(current); } } while (canTransferMore && (bytesToWrite > 0 || bytesToRead > 0) && !pendingSockets.isEmpty()); -- cgit v1.2.3