As soon as a client tries to connect to the server, the newConnection() slot will be called:
void TcpServer::newConnection() { while (m_server->hasPendingConnections()) { QTcpSocket *socket = m_server->nextPendingConnection(); m_clients << socket; ui->disconnectClients->setEnabled(true); connect(socket, &QTcpSocket::disconnected, this, &TcpServer::removeConnection); connect(socket, &QTcpSocket::readyRead, this, &TcpServer::readyRead); ui->log->appendPlainText(tr("* New connection: %1, port %2\n") .arg(socket->peerAddress().toString()) .arg(socket->peerPort())); } }