summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qhash.cpp10
-rw-r--r--src/corelib/tools/qhash.h9
-rw-r--r--src/tools/moc/generator.cpp2
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp6
4 files changed, 25 insertions, 2 deletions
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index 9ca49f13eb..112a492526 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -2538,6 +2538,16 @@ size_t qHash(long double key, size_t seed) noexcept
\sa insert()
*/
+
+/*! \fn template <class Key, class T> QMultiHash &QMultiHash<Key, T>::unite(const QHash<Key, T> &other)
+ \since 6.0
+
+ Inserts all the items in the \a other hash into this hash
+ and returns a reference to this hash.
+
+ \sa insert()
+*/
+
/*! \fn template <class Key, class T> QList<Key> QMultiHash<Key, T>::uniqueKeys() const
\since 5.13
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 67b3e026df..1f0d5d76ad 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -1219,7 +1219,7 @@ public:
return *this;
}
- QMultiHash(const QHash<Key, T> &other)
+ explicit QMultiHash(const QHash<Key, T> &other)
: QMultiHash(other.begin(), other.end())
{}
void swap(QMultiHash &other) noexcept { qSwap(d, other.d); qSwap(m_size, other.m_size); }
@@ -1808,6 +1808,13 @@ public:
return *this;
}
+ QMultiHash &unite(const QHash<Key, T> &other)
+ {
+ for (auto cit = other.cbegin(); cit != other.cend(); ++cit)
+ insert(cit.key(), *cit);
+ return *this;
+ }
+
QPair<iterator, iterator> equal_range(const Key &key)
{
detach();
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp
index 9a1998e764..78829ce93c 100644
--- a/src/tools/moc/generator.cpp
+++ b/src/tools/moc/generator.cpp
@@ -465,7 +465,7 @@ void Generator::generateCode()
// Build extra array
//
QList<QByteArray> extraList;
- QMultiHash<QByteArray, QByteArray> knownExtraMetaObject = knownGadgets;
+ QMultiHash<QByteArray, QByteArray> knownExtraMetaObject(knownGadgets);
knownExtraMetaObject.unite(knownQObjectClasses);
for (int i = 0; i < cdef->propertyList.count(); ++i) {
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index d63ed7043e..3174bd60b8 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -1320,6 +1320,12 @@ void tst_QHash::qmultihash_specific()
QVERIFY(map1.remove(42,5));
QVERIFY(map2.remove(42,5));
QVERIFY(map1 == map2);
+
+ QHash<int, int> hash;
+ hash.insert(-1, -1);
+ map2.unite(hash);
+ QCOMPARE(map2.count(), 6);
+ QCOMPARE(map2[-1], -1);
}
}