[Qt-interest] QMultiHash operator== not working as expected
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Fri Oct 2 12:07:13 CEST 2009
Christian is right...
This is a bug in QT :)
The problem is the this...
QHash's operator == is NOT sufficient for QMultiHash, since the "value list" in this case 1,2 has to be equal to 2,1. And its not according to the code for operator==
The operator== basically goes over each key in the lhs hash, finds that in the rhs hash. The it compares the value, the first lhs is 1, the first rhs value is 2. And it fails..
The next lhs iteration would yield 2 and 1...
This is a QT bug and should be filed as such... Note...Christian you could of found this, by simply looking at the code in qhash.h
Scott
-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Christian
Sent: Friday, October 02, 2009 1:53 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] QMultiHash operator== not working as expected
Hi,
well im not mixing value and key. I have keys that are mapped to
multiple values and therefore i used MultiHash. The insert method of
QmultiHash does not replace. It creates a new entry (as stated in the
documentation). You can see that because the size of both hashes is 2.
So i think my problem still remains.
Best Regards
Christian
-----Ursprüngliche Nachricht-----
Von: Carlos Manuel Duclos Vergara [mailto:carlos.duclos at nokia.com]
Gesendet: Freitag, 2. Oktober 2009 10:32
An: qt-interest at trolltech.com
Cc: Christian
Betreff: Re: [Qt-interest] QMultiHash operator== not working as expected
Hi,
[...]
>
> 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?
>
The output is correct, the problem is you are mixing keys and values.
The
first parameter of insert is the key, not the value.
If you do:
hash1.insert("a", 1);
hash1.insert("a", 2);
hash2.insert("a", 2);
hash2.insert("a", 1);
Then you are replacing the corresponding value in the hash since both
have the
same key.
Regards
--
Carlos Manuel Duclos Vergara
Senior Software Engineer, QA/Team Lead
Nokia, Qt Software
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list