What just happened?

First, we posted the request and fetched the pointer to the QNetworkReply object. Then, we connected the reply's finished signal to the mapper's slot map(). Next, we called the setMapping() method of the mapper to indicate that the sender itself should be sent as the slot's argument. The effect is very similar to the direct use of the QNetworkAccessManager::finished(QNetworkReply *reply) signal, but this way, we can use multiple slots dedicated to different purposes (with a separate mapper corresponding to each slot), all served by a single QNetworkAccessManager instance.

QSignalMapper also allows you to map with int or QString as an identifier instead of QObject *, as used in the preceding code. So, you can rewrite the ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition 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.