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
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