diff --git a/src/corelib/ipc/qtipccommon.cpp b/src/corelib/ipc/qtipccommon.cpp index be9383f38aa..a2cc75b4b15 100644 --- a/src/corelib/ipc/qtipccommon.cpp +++ b/src/corelib/ipc/qtipccommon.cpp @@ -482,6 +482,22 @@ void QNativeIpcKey::setNativeKey_internal(const QString &) { } +/*! + \fn size_t QNativeIpcKey::qHash(const QNativeIpcKey &ipcKey) noexcept + + Returns the hash value for \a ipcKey, using a default seed of \c 0. +*/ + +/*! + \fn size_t QNativeIpcKey::qHash(const QNativeIpcKey &ipcKey, size_t seed) noexcept + + Returns the hash value for \a ipcKey, using \a seed to seed the calculation. +*/ +size_t qHash(const QNativeIpcKey &ipcKey, size_t seed) noexcept +{ + return qHashMulti(seed, ipcKey.key, ipcKey.type()); +} + /*! \fn bool QNativeIpcKey::operator==(const QNativeIpcKey &lhs, const QNativeIpcKey &rhs) noexcept \fn bool QNativeIpcKey::operator!=(const QNativeIpcKey &lhs, const QNativeIpcKey &rhs) noexcept diff --git a/src/corelib/ipc/qtipccommon.h b/src/corelib/ipc/qtipccommon.h index 34d6edf03d6..73b17c1578b 100644 --- a/src/corelib/ipc/qtipccommon.h +++ b/src/corelib/ipc/qtipccommon.h @@ -158,6 +158,10 @@ private: constexpr bool isSlowPath() const noexcept { return Q_UNLIKELY(typeAndFlags.isExtended); } + friend Q_CORE_EXPORT size_t qHash(const QNativeIpcKey &ipcKey, size_t seed) noexcept; + friend size_t qHash(const QNativeIpcKey &ipcKey) noexcept + { return qHash(ipcKey, 0); } + friend bool operator==(const QNativeIpcKey &lhs, const QNativeIpcKey &rhs) noexcept { if (lhs.key != rhs.key) diff --git a/tests/auto/corelib/ipc/qnativeipckey/tst_qnativeipckey.cpp b/tests/auto/corelib/ipc/qnativeipckey/tst_qnativeipckey.cpp index e3fefdde9e7..7b08e642afd 100644 --- a/tests/auto/corelib/ipc/qnativeipckey/tst_qnativeipckey.cpp +++ b/tests/auto/corelib/ipc/qnativeipckey/tst_qnativeipckey.cpp @@ -16,6 +16,7 @@ private slots: void construct(); void getSetCheck(); void equality(); + void hash(); void swap(); void toString_data(); void toString(); @@ -182,6 +183,14 @@ void tst_QNativeIpcKey::equality() QVERIFY(!(key1 != key2)); } +void tst_QNativeIpcKey::hash() +{ + QNativeIpcKey key1("key1", QNativeIpcKey::DefaultTypeForOs); + QNativeIpcKey key2(key1); + QCOMPARE_EQ(qHash(key1), qHash(key2)); + QCOMPARE_EQ(qHash(key1, 123), qHash(key2, 123)); +} + void tst_QNativeIpcKey::swap() { QNativeIpcKey key1("key1", QNativeIpcKey::Type::PosixRealtime);