qt5base-lts/examples/network
Marc Mutz 54590c4f8a Torrent example: rewrite some very convoluted code
The old code iterated over the peer list, inserting active peers into
a QSet, curiously not stopping to search for clients if it had already
determined the peer to be active.

It then iterated over the peers again, storing the indexes of the
peers it had determined to be active in the first loop, in a QList.

It _then_ iterated over the index list, in reverse, calling removeAt()
on the peers list.

<sean parent>That's a remove_if!</sean parent>

The twist is, that only some maximum number of inactive peers should
be removed, just enough to bring the number of peers below a
predefined number.

To solve, use a lambda that keeps track of the number of times it has
returned true, returning false once the count drops to zero. We can't
use a mutable lambda here, since the STL algorithms are allowed to
copy the predicate as many times as they wish, and, indeed, remove_if
is commonly implemented by calling find_if. But the standard
guarantees exactly one application of the predicate per element, so we
can assume that we're not called again on the same element, and
therefore keep a reference to an external count.

With this, what was a horrible mess becomes a single call to remove_if.

Also change a while(--n) c.removeFirst() loop to a single call of
range-erase.

Change-Id: I6c6a54a1805e5b376800e1116e7aec643e95e4e1
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2019-05-24 12:27:36 +00:00
..
bearermonitor Migrate Windows system libs to external dependencies 2019-05-08 08:30:02 +00:00
blockingfortuneclient Examples: Replace 'Q_DECL_OVERRIDE' by 'override' 2016-06-15 09:32:30 +00:00
broadcastreceiver qtlite: Skip building examples when configured with no-feature-udpsocket 2018-01-11 12:37:50 +00:00
broadcastsender qtlite: Skip building examples when configured with no-feature-udpsocket 2018-01-11 12:37:50 +00:00
dnslookup Merge remote-tracking branch 'origin/5.12' into 5.13 2019-02-19 01:00:08 +01:00
doc Document DTLS examples 2018-08-09 03:52:13 +00:00
download Add cmdline feature to qmake 2019-02-18 07:12:14 +00:00
downloadmanager Add cmdline feature to qmake 2019-02-18 07:12:14 +00:00
fortuneclient qtlite: Skip building examples when configured with no-feature-itemviews 2018-01-12 07:58:20 +00:00
fortuneserver Change almost all other uses of qrand() to QRandomGenerator 2017-11-08 09:14:03 +00:00
googlesuggest Fix some deprecation warnings in examples 2019-02-06 22:12:23 +00:00
http Network examples: cleanup foreach usage 2019-01-06 13:39:49 +00:00
loopback Fix usage of QGuiApplication::set/resetOverrideCursor 2018-11-05 21:57:43 +00:00
multicastreceiver qtlite: Skip building examples when configured with no-feature-udpsocket 2018-01-11 12:37:50 +00:00
multicastsender qtlite: Skip building examples when configured with no-feature-udpsocket 2018-01-11 12:37:50 +00:00
multistreamclient Replace Q_DECL_OVERRIDE with override where possible 2017-09-19 11:53:42 +00:00
multistreamserver Replace Q_DECL_OVERRIDE with override where possible 2017-09-19 11:53:42 +00:00
network-chat Network examples: cleanup foreach usage 2019-01-06 13:39:49 +00:00
securesocketclient QtBase: compile examples with QT_DISABLE_DEPRECATED_BEFORE=0x050d00 2019-02-13 05:55:46 +00:00
secureudpclient Document DTLS examples 2018-08-09 03:52:13 +00:00
secureudpserver DTLS server - use the proper TLS configuration 2018-08-10 03:46:45 +00:00
shared Polish SCTP examples 2016-08-03 11:46:21 +00:00
threadedfortuneserver Change almost all other uses of qrand() to QRandomGenerator 2017-11-08 09:14:03 +00:00
torrent Torrent example: rewrite some very convoluted code 2019-05-24 12:27:36 +00:00
network.pro Fix builds without DTLS 2018-10-09 13:14:42 +00:00
README Remove references to demos from docs. 2011-07-05 19:57:54 +02:00

Qt is provided with an extensive set of network classes to support both
client-based and server side network programming.

These examples demonstrate the fundamental aspects of network programming
with Qt.


Documentation for these examples can be found via the Examples
link in the main Qt documentation.