Communicating between games
After having discussed Qt's high-level network classes such as QNetworkAccessManager
and QNetworkConfigurationManager
, we will now take a look at lower-level network classes and see how Qt supports you when it comes to implementing TCP or UDP servers and clients. This becomes relevant when you plan to extend your game by including a multiplayer mode. For such a task, Qt offers QTcpSocket
, QUdpSocket
, and QTcpServer
.
Time for action – Realizing a simple chat program
To get familiar with QTcpServer
and QTcpSocket
, let's develop a simple chat program. This example will teach you the basic knowledge of network handling in Qt so that you can use this skill later to connect two or more copies of a game. At the end of this exercise, we want to see something like this:

On both the left-hand side and the right-hand side of the preceding screenshot, you can see a client, whereas the server is in the middle. We'll start by taking a closer look at the server.