Improvements

The example we explained uses a nonblocking, asynchronous approach. For example, after asynchronous calls such as connectToHost(), we do not block the thread until we get a result, but instead, we connect to the socket's signals to proceed. On the Internet as well as Qt's documentation, on the other hand, you will find dozens of examples explaining the blocking and the synchronous approaches. You will easily spot them by their use of waitFor...() functions. These functions block the current thread until a function such as connectToHost() has a result—the time connected() or error() will be emitted. The corresponding blocking function to connectToHost() is waitForConnected(). The other blocking functions that can be used are waitForReadyRead() ...

Get Game Programming Using Qt now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.