With QTcpServer::listen(), we defined that the server should listen to the localhost and the port 52693 for new incoming connections. The value used here, QHostAddress::LocalHost of the QHostAddress::SpecialAddress enumeration, will resolve to 127.0.0.1. Instead, if you pass QHostAddress::Any, the server will listen to all IPv4 interfaces as well as to IPv6 interfaces. If you only want to listen to a specific address, just pass this address as QHostAddress:
m_server->listen(QHostAddress("127.0.0.1"), 0);
This will behave like the one in the preceding code, only in that the server will now listen to a port that will be chosen automatically. On success, listen() will return true. So, if something goes wrong in the example, ...