summaryrefslogtreecommitdiffstats
path: root/src/network/kernel
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-11-29 15:30:52 +0100
committerJani Heikkinen <jani.heikkinen@qt.io>2016-12-07 13:21:20 +0000
commit4077fcc6153493284b5e2b0812ff215b49e8c8b7 (patch)
tree83f2643e479437b69388255a400c981dea74f8cc /src/network/kernel
parent630f8e7ad6e94c703f85fa11a9926ba83c478e72 (diff)
QHostAddress: fix assignment operators
QHostAddress allowed assignment from a QString, but the respective constructor is explicit, and rightfully so. So it does not make sense that the assignment operator is provided, because of the asymmetry caused between QHostAddress addr = funcReturningQString(); // ERROR addr = funcReturningQString(); // OK (until now) By the same token, since SpecialAddress is implicitly convertible to QHostAddress, provide the missing assignment operator from that enum. Add tests, rewriting the _data() function to use the enum instead of an int to pass SpecialAddress values, and to test !=, too. Added setAddress(SpecialAddress), since a) it was missing and b) to share code between the ctor and the assignment operator. Change-Id: Ief64c493be13ada8c6968801d9ed083b267fa902 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network/kernel')
-rw-r--r--src/network/kernel/qhostaddress.cpp28
-rw-r--r--src/network/kernel/qhostaddress.h5
2 files changed, 33 insertions, 0 deletions
diff --git a/src/network/kernel/qhostaddress.cpp b/src/network/kernel/qhostaddress.cpp
index 7e3d2c5d6e..8fac76f86a 100644
--- a/src/network/kernel/qhostaddress.cpp
+++ b/src/network/kernel/qhostaddress.cpp
@@ -517,6 +517,19 @@ QHostAddress::QHostAddress(const QHostAddress &address)
QHostAddress::QHostAddress(SpecialAddress address)
: d(new QHostAddressPrivate)
{
+ setAddress(address);
+}
+
+/*!
+ \overload
+ \since 5.8
+
+ Sets the special address specified by \a address.
+*/
+void QHostAddress::setAddress(SpecialAddress address)
+{
+ d->clear();
+
Q_IPV6ADDR ip6;
memset(&ip6, 0, sizeof ip6);
quint32 ip4 = INADDR_ANY;
@@ -567,6 +580,7 @@ QHostAddress &QHostAddress::operator=(const QHostAddress &address)
return *this;
}
+#if QT_DEPRECATED_SINCE(5, 8)
/*!
Assigns the host address \a address to this object, and returns a
reference to this object.
@@ -578,6 +592,20 @@ QHostAddress &QHostAddress::operator=(const QString &address)
setAddress(address);
return *this;
}
+#endif
+
+/*!
+ \since 5.8
+ Assigns the special address \a address to this object, and returns a
+ reference to this object.
+
+ \sa setAddress()
+*/
+QHostAddress &QHostAddress::operator=(SpecialAddress address)
+{
+ setAddress(address);
+ return *this;
+}
/*!
\fn bool QHostAddress::operator!=(const QHostAddress &other) const
diff --git a/src/network/kernel/qhostaddress.h b/src/network/kernel/qhostaddress.h
index 58af14ee33..10fe33f6fa 100644
--- a/src/network/kernel/qhostaddress.h
+++ b/src/network/kernel/qhostaddress.h
@@ -108,7 +108,11 @@ public:
#endif
QHostAddress &operator=(const QHostAddress &other);
+#if QT_DEPRECATED_SINCE(5, 8)
+ QT_DEPRECATED_X("use = QHostAddress(string) instead")
QHostAddress &operator=(const QString &address);
+#endif
+ QHostAddress &operator=(SpecialAddress address);
void swap(QHostAddress &other) Q_DECL_NOTHROW { d.swap(other.d); }
@@ -118,6 +122,7 @@ public:
void setAddress(const Q_IPV6ADDR &ip6Addr);
void setAddress(const sockaddr *address);
bool setAddress(const QString &address);
+ void setAddress(SpecialAddress address);
QAbstractSocket::NetworkLayerProtocol protocol() const;
quint32 toIPv4Address() const; // ### Qt6: merge with next overload