View Full Version : Qt LinkedHashMap
Jimmy2775
24th July 2007, 21:40
I've looked through the Qt documentation and I cannot find a collection class that uses key/value pairings and maintains insertion order. QMap comes closest, but it sorts the keys. What I need is an equivalent to Java's LinkedHashMap. Does such a thing exist in Qt? If not, I would greatly appreciate any ideas you might have regarding strategies for implementing something like this in Qt. I'm not too sure where to begin...
Thanks,
Jimmy
fullmetalcoder
24th July 2007, 21:42
There's no such thing but you can do it quite easily by grouping to QList<> objects
template <typename Key, typename T>
class OrderedMap
{
public:
// ... all your functions here, straigtforward enough to use indexOf()...
private:
QList<Key> m_keys;
QList<T> m_values;
};
Jimmy2775
24th July 2007, 21:44
When you put it that way, it seems awfully simple. Thanks, FullMetalCoder.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.