Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Combine multiple QHashes into one QHash

Tags:

c++

hash

qt

I have two QHashes, and I want to combine them into one QHash. Both hashes are of the same type (ie, both are QHash<QString, qint32>). How do I do this efficiently (and/or Qt-like)?

Something like:

hash1 << hash2;

or

hash1.append( hash2 );

or similar, would be awesome. If that's not possible, I'll just loop through the smaller hash and insert it into the first.

like image 415
Freedom_Ben Avatar asked Jun 23 '14 22:06

Freedom_Ben


2 Answers

I suppose you are looking for QHash::unite().

As stated in the linked documentation:

Inserts all the items in the other hash into this hash. If a key is common to both hashes, the resulting hash will contain the key multiple times.

like image 163
Silicomancer Avatar answered Oct 20 '22 08:10

Silicomancer


The unite function has become obsolete as of Qt 5.15. The best solution is QHash::insert.

like image 2
Vincent Fourmond Avatar answered Oct 20 '22 07:10

Vincent Fourmond