Results 1 to 3 of 3

Thread: Qt LinkedHashMap

  1. #1
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Qt LinkedHashMap

    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

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt LinkedHashMap

    There's no such thing but you can do it quite easily by grouping to QList<> objects

    Qt Code:
    1. template <typename Key, typename T>
    2. class OrderedMap
    3. {
    4. public:
    5. // ... all your functions here, straigtforward enough to use indexOf()...
    6. private:
    7. QList<Key> m_keys;
    8. QList<T> m_values;
    9. };
    To copy to clipboard, switch view to plain text mode 
    Current Qt projects : QCodeEdit, RotiDeCode

  3. The following user says thank you to fullmetalcoder for this useful post:

    Jimmy2775 (24th July 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt LinkedHashMap

    When you put it that way, it seems awfully simple. Thanks, FullMetalCoder.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.