From 098a3855650c16f08df1e24139cd0cbac9b112c2 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 8 May 2017 19:22:30 +0900 Subject: Make QNetworkAccessManager member a singleton As Qt documentation advises, a single QNetworkAccessManager is enough for the whole Qt application. --- connectiondata.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/connectiondata.cpp b/connectiondata.cpp index a6d80d53..483d2f0c 100644 --- a/connectiondata.cpp +++ b/connectiondata.cpp @@ -24,27 +24,27 @@ using namespace QMatrixClient; -class ConnectionData::Private +QNetworkAccessManager* getNam() { - public: - Private() : nam(nullptr) { } - - QUrl baseUrl; - QString accessToken; - QString lastEvent; - QNetworkAccessManager* nam; + static QNetworkAccessManager* _nam = new QNetworkAccessManager(); + return _nam; +} + +struct ConnectionData::Private +{ + QUrl baseUrl; + QString accessToken; + QString lastEvent; }; ConnectionData::ConnectionData(QUrl baseUrl) : d(new Private) { d->baseUrl = baseUrl; - d->nam = new QNetworkAccessManager(); } ConnectionData::~ConnectionData() { - d->nam->deleteLater(); delete d; } @@ -60,7 +60,7 @@ QUrl ConnectionData::baseUrl() const QNetworkAccessManager* ConnectionData::nam() const { - return d->nam; + return getNam(); } void ConnectionData::setToken(QString token) -- cgit v1.2.3