Hi all, I put some elements in the QHash in an order, but the retrieve order was changed while I use it's iterator. Need help !
Thanks
Hi all, I put some elements in the QHash in an order, but the retrieve order was changed while I use it's iterator. Need help !
Thanks
QHash uses a tree to store elements, so that the lookup time is optimial, so the order of elements is not preserved. If you need the order of the elements to be maintained, use QMap instead, just be prepared for slower lookups.
bruce1007 (26th August 2006)
That's the way QHash operates. Why? Because it's a hash! To quote the documentation: "QHash is unordered, so an iterator's sequence cannot be assumed to be predictable. If ordering by key is required, use a QMap."
For more information, lookup hashes and maps in your nearest algorithms and data structures textbook. If you don't have one, get one, and consult wikipedia in the meantime.
bruce1007 (26th August 2006)
Bookmarks