Sorting QList<QMap<QString , qreal > >
-
wrote on 7 May 2011, 11:21 last edited by
Hi
I have a container in this form : QList<QMap<QString , qreal > > myContainer .
How can I sort this QList according to qreal ? -
wrote on 7 May 2011, 11:46 last edited by
Which qreal? Since each QMap (form the QList) can have many qreal values? Tell us what are you trying to do so that we can give some advice about that.
-
wrote on 7 May 2011, 12:34 last edited by
Hi,
Use "qSort":http://doc.qt.nokia.com/4.7.1/qtalgorithms.html#qSort or "qStableSort":http://doc.qt.nokia.com/4.7.1/qtalgorithms.html#qStableSort from "Qt Generic Algorithms":http://doc.qt.nokia.com/qq/qq15-qalgorithms.html
Best regards,
Leon -
wrote on 7 May 2011, 12:47 last edited by
[quote author="leon.anavi" date="1304771691"]Hi,
Use "qSort":http://doc.qt.nokia.com/4.7.1/qtalgorithms.html#qSort or "qStableSort":http://doc.qt.nokia.com/4.7.1/qtalgorithms.html#qStableSort from "Qt Generic Algorithms":http://doc.qt.nokia.com/qq/qq15-qalgorithms.html
Best regards,
Leon[/quote]On which base should he sort?
he has a
@
class MyContainer : QMap<QString , qreal>{};
QList<MyContainer>;
@To use qSort, MyContainer needs a less then operator.
-
wrote on 7 May 2011, 12:57 last edited by
He can use the "qSort(...)":http://doc.qt.nokia.com/4.7.1/qtalgorithms.html#qSort-2 overload that takes an less-than function.
But i have a feeling that he wants something different - because i can't imagine what criteria he wants to use to sort a vector of maps - this is why i asked more information.
-
wrote on 7 May 2011, 13:11 last edited by
[quote author="Gerolf" date="1304772427"]
On which base should he sort?he has a
@
class MyContainer : QMap<QString , qreal>{};
QList<MyContainer>;
@To use qSort, MyContainer needs a less then operator.
[/quote]
Hi Gerolf,
I have no idea what is the exact goal as the combination of QMap and QList is a bit strange for sorting :)
@
void qSort ( RandomAccessIterator begin, RandomAccessIterator end, LessThan lessThan )
@Can't he use custom lessThan method which compares QMap<QString , qreal > in a desired way (whatever it is) and fits his needs?
amiref, please provide more details as suggested by Zlatomir
Thanks,
Leon -
wrote on 7 May 2011, 18:18 last edited by
[quote author="leon.anavi" date="1304773869"]
Hi Gerolf,
I have no idea what is the exact goal as the combination of QMap and QList is a bit strange for sorting :)@
void qSort ( RandomAccessIterator begin, RandomAccessIterator end, LessThan lessThan )
@Can't he use custom lessThan method which compares QMap<QString , qreal > in a desired way (whatever it is) and fits his needs?
amiref, please provide more details as suggested by Zlatomir
[/quote]Yes, he can, that's right. But I'm looking for the logic on sorting a list of qmaps....
1/7