PDA

View Full Version : How to sort QMap



mamyte03@gmail.com
9th November 2007, 10:51
I have a QMap<QString, QString> allSources in witch key is a "table_by_view" names, as vlues is "view_title".
Example:
"Activity_view", "Activiti";
"pOrders_view","orders";
"car_specification_view", "cars";

And so on.

But now I need to sord by order "view_title". A/b/s and so on..
How can I do this, for get :
"activity_view","activity";
"car_specification_view","cars"
"pOrders_view", "orders";

Now i get only values as QStringList , sorting it and geting values in right order, but key in old order...

wysota
9th November 2007, 10:54
A map is an associative container, it stores its values sorted by keys to improve access speed to values. There is no way of sorting a map by value order. You have to use QList<QPair<x,y>> instead.

mchara
9th November 2007, 11:11
or, if you need only sorted titles without associations to keys, use


QStringList list = QMap::values();
qSort(list.begin(), list.end());


U may get associated keys by calling QMap::key(const T & value );