[Interest] How to make the QString "10" behind "9" in QMap's key order
mail at herrdiel.de
mail at herrdiel.de
Sun Jan 7 09:51:31 CET 2018
Hi,
you need a "lessThan"-function, tailored for your needs. An example from
me is this:
boolPerson::lessThanFamilyFirst(QSharedPointer<Person>p1,QSharedPointer<Person>p2)
{
return(QString::localeAwareCompare(p1->familyName(),p2->familyName())<0)
||((p1->familyName()==p2->familyName())
&&(QString::localeAwareCompare(p1->firstName(),p2->firstName())<0));
}
Now you can pass this as a functor to a sort method like this:
std::stable_sort(pupils.begin(),pupils.end(),Person::lessThanFamilyFirst);
Please notice, that there are no () when calling the lessThan functor.
HTH
Sebastian
Am 07.01.2018 um 09:01 schrieb jack ma:
> Hi,
>
> there is a QMap<QString,QGraphicsItem *> type, then insert values with:
>
> type.insert("U1",nullptr),
> type.insert("U2",nullptr),
> …………
> type.insert("U9",nullptr),
> type.insert("U10",nullptr),
>
> I want get the values follow the order of U1, U2 ... U10, but the
> default order is U1, U10 ,……U9
>
> I know this is a common string sorting problem, but I do not know how
> to solve it well.
>
> Any suggestions are very grateful !
> Thanks.
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
--
http://www.classintouch.de - Tablet-Software für Lehrer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180107/fa6c294d/attachment.html>
More information about the Interest
mailing list