Qt技巧:全局QNetworkAccessManager
本文主要介绍如何在程序内保持单一实例进行网络访问
由来:
根据Qt文档:
The QNetworkAccessManager class allows the application to send network requests and receive replies
The Network Access API is constructed around one QNetworkAccessManager object, which holds the common configuration and settings for the requests it sends. It contains the proxy and cache configuration, as well as the signals related to such issues, and reply signals that can be used to monitor the progress of a network operation. One QNetworkAccessManager should be enough for the whole Qt application.
我们应该尽量只使用一个QNetworkAccessManager实例进行网络访问
技巧:
main.h
QNetworkAccessManager *getGlobalNetworkManager();
main.cpp
static QPointer<QNetworkAcces