Game Programming using Qt 5 Beginner's Guide - Second Edition
by Pavel Strakhov, Witold Wysota, Lorenz Haas
What just happened?
Since more than one connection may be pending, we use hasPendingConnections() to determine whether there is at least one more pending connection. Each one is then handled in the iteration of the while loop. To get a pending connection of the QTcpSocket type, we call nextPendingConnection() and add this connection to a private vector called m_clients, which holds all active connections. In the next line, as there is now at least one connection, we enable the button that allows all connections to be closed. The slot connected to the button's click() signal will call QTcpSocket::close() on each single connection. When a connection is closed, its socket emits a disconnected() signal. We connect this signal to our removeConnection() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access