[Qt-interest] QMultiHash operator== not working as expected
Christian
christian.doering at uni-muenster.de
Fri Oct 2 10:20:49 CEST 2009
Hi all,
I am working with Qt 4.4 and i have 2 QMultiHash<QString, int>. I want
to compare both hashes. The problem is that i only get true for the
comparison when the items in both hashes are inserted in same order. Let
me give you some code.
#include <QString>
#include <QMultiHash>
#include <iostream>
int main(int argc, char* argv[]) {
QMultiHash<QString, int> hash1;
QMultiHash<QString, int> hash2;
hash1.insert("a", 1);
hash1.insert("a", 2);
hash2.insert("a", 2);
hash2.insert("a", 1);
// the output is: "unequal"
if (hash1 == hash2)
std::cout << "equal" << std::endl;
else
std::cout << "unequal" << std::endl;
hash2.clear();
hash2.insert("a", 1);
hash2.insert("a", 2);
// the output is: "equal"
if (hash1 == hash2)
std::cout << "equal" << std::endl;
else
std::cout << "unequal" << std::endl;
return 0;
}
If i look into documentation for the operator the following is stated:
"Two hashes are considered equal if they contain the same (key, value)
pairs." So in my opinion both comparisons in my code should return true
but that is not the case. Is this behaviour intended? If so, what
structure can i use instead?
Best Regards
Christian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091002/226b3cd6/attachment.html
More information about the Qt-interest-old
mailing list