Results 1 to 2 of 2

Thread: How to reverse the order of the same keys when inserted using QMultiMap

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to reverse the order of the same keys when inserted using QMultiMap

    Hi,
    I have a QMultiMap<QString, QString> data structure.
    Now, I want to insert the different QString values to the same key. The insertion is just based in the insertion order.
    For example if I do
    map.insert("mykey", "myvalue_1");
    map.insert("mykey", "myvalue_2");
    map.insert("mykey", "myvalue_3");
    map.insert("mykey", "myvalue_4");

    I would have the values in this order:

    1. "myvalue_1"
    2. "myvalue_2"
    3. "myvalue_3"
    4. "myvalue_4"

    But what I have is:

    1. "myvalue_4"
    2. "myvalue_3"
    3. "myvalue_2"
    4. "myvalue_1"

    From the QMultiMap::insert documentation it says that values belonging to the same key are inserted in reverse order.
    How can I achieve what I need?

    I tried with
    map.insert(map.constEnd(), "mykey", "myvalue_1"); but the result is the same

    Thank you
    Franco Amato

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to reverse the order of the same keys when inserted using QMultiMap

    Hi, maybe QMultiMap is not the container you need. For example you could use a QMap<QString,QStringList>, and push your new values into the stringlist instead of using multiple insert commands.

    Ginsengelf

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

    franco.amato (15th February 2022)

Similar Threads

  1. Replies: 3
    Last Post: 7th November 2019, 19:10
  2. Replies: 8
    Last Post: 31st August 2016, 10:44
  3. Replies: 1
    Last Post: 17th April 2012, 16:53
  4. QMultiMap And QDataStream
    By amiref in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2011, 11:50
  5. Reverse Order on QStringList slow...?
    By patrik08 in forum Qt Programming
    Replies: 24
    Last Post: 21st February 2007, 10:32

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.