Add swap and move operator to QHostInfo
Also mark as shared-come-qt6, [ChangeLog][QtNetwork][QHostInfo] Added swap() and move operator. Change-Id: I8f422868f0487a37aeba3bc74685dc4912e9b3a4 Coverity-Id: 168204 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
cafefd1d33
commit
904788e3c6
@ -278,6 +278,27 @@ int QHostInfo::lookupHost(const QString &name, QObject *receiver,
|
||||
return id;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QHostInfo &QHostInfo::operator=(QHostInfo &&other)
|
||||
|
||||
Move-assigns \a other to this QHostInfo instance.
|
||||
|
||||
\note The moved-from object \a other is placed in a
|
||||
partially-formed state, in which the only valid operations are
|
||||
destruction and assignment of a new value.
|
||||
|
||||
\since 5.10
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QHostInfo::swap(QHostInfo &other)
|
||||
|
||||
Swaps host-info \other with this host-info. This operation is
|
||||
very fast and never fails.
|
||||
|
||||
\since 5.10
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn int QHostInfo::lookupHost(const QString &name, const QObject *receiver, PointerToMemberFunction function)
|
||||
|
||||
|
@ -63,8 +63,11 @@ public:
|
||||
explicit QHostInfo(int lookupId = -1);
|
||||
QHostInfo(const QHostInfo &d);
|
||||
QHostInfo &operator=(const QHostInfo &d);
|
||||
QHostInfo &operator=(QHostInfo &&other) Q_DECL_NOTHROW { swap(other); return *this; }
|
||||
~QHostInfo();
|
||||
|
||||
void swap(QHostInfo &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
|
||||
|
||||
QString hostName() const;
|
||||
void setHostName(const QString &name);
|
||||
|
||||
@ -154,6 +157,8 @@ private:
|
||||
QtPrivate::QSlotObjectBase *slotObj);
|
||||
};
|
||||
|
||||
Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QHostInfo)
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(QHostInfo)
|
||||
|
@ -86,6 +86,8 @@ class tst_QHostInfo : public QObject
|
||||
private slots:
|
||||
void init();
|
||||
void initTestCase();
|
||||
void swapFunction();
|
||||
void moveOperator();
|
||||
void getSetCheck();
|
||||
void staticInformation();
|
||||
void lookupIPv4_data();
|
||||
@ -129,6 +131,29 @@ private:
|
||||
#endif
|
||||
};
|
||||
|
||||
void tst_QHostInfo::swapFunction()
|
||||
{
|
||||
QHostInfo obj1, obj2;
|
||||
obj1.setError(QHostInfo::HostInfoError(0));
|
||||
obj2.setError(QHostInfo::HostInfoError(1));
|
||||
obj1.swap(obj2);
|
||||
QCOMPARE(QHostInfo::HostInfoError(0), obj2.error());
|
||||
QCOMPARE(QHostInfo::HostInfoError(1), obj1.error());
|
||||
}
|
||||
|
||||
void tst_QHostInfo::moveOperator()
|
||||
{
|
||||
QHostInfo obj1, obj2, obj3(1);
|
||||
obj1.setError(QHostInfo::HostInfoError(0));
|
||||
obj2.setError(QHostInfo::HostInfoError(1));
|
||||
obj1 = std::move(obj2);
|
||||
obj2 = obj3;
|
||||
QCOMPARE(QHostInfo::HostInfoError(1), obj1.error());
|
||||
QCOMPARE(obj3.lookupId(), obj2.lookupId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Testing get/set functions
|
||||
void tst_QHostInfo::getSetCheck()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user