aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-05-08 19:22:30 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-05-08 19:38:42 +0900
commit098a3855650c16f08df1e24139cd0cbac9b112c2 (patch)
tree75f4962defe9c5c1836603f700ebb8d9393d1a6f
parent096a05d59654244f7c928dc5f2537a760070a577 (diff)
downloadlibquotient-098a3855650c16f08df1e24139cd0cbac9b112c2.tar.gz
libquotient-098a3855650c16f08df1e24139cd0cbac9b112c2.zip
Make QNetworkAccessManager member a singleton
As Qt documentation advises, a single QNetworkAccessManager is enough for the whole Qt application.
-rw-r--r--connectiondata.cpp22
1 files 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)