Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sorting QList<QMap<QString , qreal > >

Sorting QList<QMap<QString , qreal > >

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 8.0k Views
  • 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 Offline
    A Offline
    amiref
    wrote on last edited by
    #1

    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
    0
    • ZlatomirZ Offline
      ZlatomirZ Offline
      Zlatomir
      wrote on last edited by
      #2

      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
      0
      • L Offline
        L Offline
        leon.anavi
        wrote on last edited by
        #3

        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
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          [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
          0
          • ZlatomirZ Offline
            ZlatomirZ Offline
            Zlatomir
            wrote on last edited by
            #5

            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
            0
            • L Offline
              L Offline
              leon.anavi
              wrote on last edited by
              #6

              [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
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                [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
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved