diff options
-rw-r--r-- | src/corelib/plugin/quuid.cpp | 11 | ||||
-rw-r--r-- | src/corelib/plugin/quuid.h | 2 | ||||
-rw-r--r-- | tests/auto/quuid/tst_quuid.cpp | 11 |
3 files changed, 24 insertions, 0 deletions
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index ad182eb9bf..6fca1b6709 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -927,4 +927,15 @@ QUuid QUuid::createUuid() guid; otherwise returns false. */ +/** + Returns a hash of the QUuid + */ +uint qHash(const QUuid &uuid) +{ + return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) + ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) + ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]); +} + + QT_END_NAMESPACE diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index 28feff13d2..b941079df0 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -189,6 +189,8 @@ Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QUuid &); Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUuid &); #endif +Q_CORE_EXPORT uint qHash(const QUuid &uuid); + QT_END_NAMESPACE QT_END_HEADER diff --git a/tests/auto/quuid/tst_quuid.cpp b/tests/auto/quuid/tst_quuid.cpp index 4948312fd4..5761ea1a8c 100644 --- a/tests/auto/quuid/tst_quuid.cpp +++ b/tests/auto/quuid/tst_quuid.cpp @@ -82,6 +82,8 @@ private slots: void threadUniqueness(); void processUniqueness(); + void hash(); + public: // Variables QUuid uuidA; @@ -322,5 +324,14 @@ void tst_QUuid::processUniqueness() QVERIFY(processOneOutput != processTwoOutput); } +void tst_QUuid::hash() +{ + uint h = qHash(uuidA); + QCOMPARE(qHash(uuidA), h); + QCOMPARE(qHash(QUuid(uuidA.toString())), h); +} + + + QTEST_MAIN(tst_QUuid) #include "tst_quuid.moc" |