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() ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.