The chatServer will trigger the newConnection() signal whenever a client has connected to the server, so we connect that signal to our custom slot function called newClientConnection(). The slot function looks like this:
void server::newClientConnection()
{
QTcpSocket* client = chatServer->nextPendingConnection();
QString ipAddress = client->peerAddress().toString();
int port = client->peerPort();
connect(client, &QTcpSocket::disconnected, this, &server::socketDisconnected); connect(client, &QTcpSocket::readyRead, this, &server::socketReadyRead); connect(client, &QTcpSocket::stateChanged, this, &server::socketStateChanged); allClients->push_back(client); qDebug() << "Socket connected from " + ipAddress + ":" + QString::number(port); ...