Reverse iterate on QMultiMap
-
wrote on 19 Nov 2019, 10:41 last edited by Josz
Hello, maybe its a very treated theme, but in moment I coud not find a satisfactory answer in google.
I have the next QMultiMap List:
QMultiMap<QString, QString> data; data.insert("John", "Young"); data.insert("John", "Tall"); data.insert("Mike", "Short"); data.insert("Mike", "Good man"); data.insert("John", "Clueless"); data.insert("Mike", "Long hair"); for(const QString &name : data.uniqueKeys()){ QStringList aux = data.values(nombre); qDebug() << "Name: " << name; for(const QString &aux2 : aux) { qDebug() << aux2; } }
The code produces the next output
Name: "John" "Clueless" "Tall" "Young" Name: "Mike" "Long hair" "Good man" "Short"
The list is in The list is in random order displayed.
Is there a way to show the elements in reverse order? .... Or in a determined order, for example, alphabetical?
Thanks in avance.
-
Hello, maybe its a very treated theme, but in moment I coud not find a satisfactory answer in google.
I have the next QMultiMap List:
QMultiMap<QString, QString> data; data.insert("John", "Young"); data.insert("John", "Tall"); data.insert("Mike", "Short"); data.insert("Mike", "Good man"); data.insert("John", "Clueless"); data.insert("Mike", "Long hair"); for(const QString &name : data.uniqueKeys()){ QStringList aux = data.values(nombre); qDebug() << "Name: " << name; for(const QString &aux2 : aux) { qDebug() << aux2; } }
The code produces the next output
Name: "John" "Clueless" "Tall" "Young" Name: "Mike" "Long hair" "Good man" "Short"
The list is in The list is in random order displayed.
Is there a way to show the elements in reverse order? .... Or in a determined order, for example, alphabetical?
Thanks in avance.
wrote on 19 Nov 2019, 10:59 last edited by JonB@Josz
I assume you mean the "multi-items" associated with each key in reverse order. Then don't usefor(const QString &aux2 : aux)
: use a reverse iterator, or count down fromaux.length() - 1
yourself, or reverse theQStringList
. -
@Josz
I assume you mean the "multi-items" associated with each key in reverse order. Then don't usefor(const QString &aux2 : aux)
: use a reverse iterator, or count down fromaux.length() - 1
yourself, or reverse theQStringList
. -
wrote on 19 Nov 2019, 13:21 last edited by
QMap iterators are bidirectional:
for(auto i = map.keyEnd()-1;i!=map.keyBegin();--i)
1/4