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

Single network manager per application

One single instance of QNetworkAccessManager is enough for an entire application. For example, you can create an instance of QNetworkAccessManager in your main window class and pass a pointer to it to all the other places where it's needed. For ease of use, you can also create a singleton and access the manager through that.

A singleton pattern ensures that a class is instantiated only once. The pattern is useful for accessing application-wide configurations or—as in our case—an instance of QNetworkAccessManager.

A simple template-based approach to create a singleton will look like this (as a header file):

template <class T> class Singleton { public: static T& instance() { static T static_instance; return ...

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