O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What just happened?

The m_socket private member variable holds an instance of QTcpSocket. If this socket is already connected, nothing happens. Otherwise, the socket is connected to the given address and port by calling connectToHost(). Besides the obligatory server address and port number, you can pass a third argument to define the mode in which the socket will be opened. For possible values, you can use OpenMode just like we did for QIODevice.

Since this call is asynchronous, we print a notification to the chat so that the user is informed that the application is currently trying to connect to the server. When the connection is established, the socket sends the connected() signal that prints "Connected to server" on the chat to indicate ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required