summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-07-13 22:52:30 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-07-15 13:07:10 +0200
commita7383b4b6dde54569e6fdfa0888e474a37416a51 (patch)
treeb3349898e646463e87599e37cec90868dd5f1e3a
parentefa183309e69f317189ef06fb1f13b60da9d7c63 (diff)
QNetworkRequest: make the default ctor implicit
As in QVarLengthArray (c34242c679aaea6ee1badf6c1e5f274f925f5f50), this will probably bite someone someday, so fix it before there's a bug report. Use ctor delegation to keep code size increase small. There's also the benefit that default-constructing a QNetworkRequest now no longer creates an expensive QUrl object just to destroy it unused again. Add an auto-test. Change-Id: I5ceb5402ca3946048d695244d1b1c36564a1e80a Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
-rw-r--r--src/network/access/qnetworkrequest.cpp13
-rw-r--r--src/network/access/qnetworkrequest.h3
-rw-r--r--tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp7
3 files changed, 21 insertions, 2 deletions
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index ba36c75419..c82eb8fe9f 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -468,13 +468,24 @@ public:
};
/*!
+ Constructs a QNetworkRequest object with no URL to be requested.
+ Use setUrl() to set one.
+
+ \sa url(), setUrl()
+*/
+QNetworkRequest::QNetworkRequest()
+ : d(new QNetworkRequestPrivate)
+{
+}
+
+/*!
Constructs a QNetworkRequest object with \a url as the URL to be
requested.
\sa url(), setUrl()
*/
QNetworkRequest::QNetworkRequest(const QUrl &url)
- : d(new QNetworkRequestPrivate)
+ : QNetworkRequest()
{
d->url = url;
}
diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h
index 846ead1592..8ad4ab41c0 100644
--- a/src/network/access/qnetworkrequest.h
+++ b/src/network/access/qnetworkrequest.h
@@ -128,7 +128,8 @@ public:
};
- explicit QNetworkRequest(const QUrl &url = QUrl());
+ QNetworkRequest();
+ explicit QNetworkRequest(const QUrl &url);
QNetworkRequest(const QNetworkRequest &other);
~QNetworkRequest();
QNetworkRequest &operator=(QNetworkRequest &&other) noexcept { swap(other); return *this; }
diff --git a/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp b/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp
index 7a3def410a..6637be0174 100644
--- a/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp
+++ b/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp
@@ -41,6 +41,7 @@ class tst_QNetworkRequest: public QObject
private slots:
void ctor_data();
void ctor();
+ void implicitDefaultCtor();
void setUrl_data();
void setUrl();
void setRawHeader_data();
@@ -78,6 +79,12 @@ void tst_QNetworkRequest::ctor()
}
}
+void tst_QNetworkRequest::implicitDefaultCtor()
+{
+ QNetworkRequest r = {};
+ Q_UNUSED(r);
+}
+
void tst_QNetworkRequest::setUrl_data()
{
ctor_data();