Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Sorting QList<QMap<QString , qreal > >

    General and Desktop
    4
    7
    7575
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      amiref 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 ?

      1 Reply Last reply Reply Quote 0
      • Zlatomir
        Zlatomir 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.

        https://forum.qt.io/category/41/romanian

        1 Reply Last reply Reply Quote 0
        • L
          leon.anavi 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

          http://anavi.org/

          1 Reply Last reply Reply Quote 0
          • G
            giesbert 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.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply Reply Quote 0
            • Zlatomir
              Zlatomir 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.

              https://forum.qt.io/category/41/romanian

              1 Reply Last reply Reply Quote 0
              • L
                leon.anavi 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

                http://anavi.org/

                1 Reply Last reply Reply Quote 0
                • G
                  giesbert 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....

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post