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. Problem with qSort of QList<CustomType>

Problem with qSort of QList<CustomType>

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 1.3k 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.
  • Ivan NetskinI Offline
    Ivan NetskinI Offline
    Ivan Netskin
    wrote on last edited by Ivan Netskin
    #1

    Hello, trying to sort QList <MyType> list. Doing this:

    qSort(list.begin(),list.end(),sortFunc);
    ....
    bool sortFunc(const MyType1& mt1, const MyType2& mt2){
    return false;
    }
    

    So the first line of code above produce error:
    error: C2064: term does not evaluate to a function taking 2 arguments.
    What's the problem guys? I've already successfully sorted QStringList that way btw. Thanks in advance!

    kshegunovK 1 Reply Last reply
    0
    • m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by
      #2

      Hi,
      your sort function looks ok. Please make sure, though, that it is not a member function of some class and you should declare it before you call qSort.
      -Michael.

      1 Reply Last reply
      3
      • Paul ColbyP Offline
        Paul ColbyP Offline
        Paul Colby
        wrote on last edited by
        #3

        One small thing to check: are you defining / declaring the sortFunc function before or after the qSort invocation? ie if the code you've shown above is all within one file, and in the order you've shown, then try moving the sortFunc function definition above the qSort call in the file.

        Cheers.

        Ivan NetskinI 1 Reply Last reply
        2
        • Ivan NetskinI Ivan Netskin

          Hello, trying to sort QList <MyType> list. Doing this:

          qSort(list.begin(),list.end(),sortFunc);
          ....
          bool sortFunc(const MyType1& mt1, const MyType2& mt2){
          return false;
          }
          

          So the first line of code above produce error:
          error: C2064: term does not evaluate to a function taking 2 arguments.
          What's the problem guys? I've already successfully sorted QStringList that way btw. Thanks in advance!

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          Let's see ... MSDN also provides comprehensive examples, by the way ...

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          2
          • Ivan NetskinI Offline
            Ivan NetskinI Offline
            Ivan Netskin
            wrote on last edited by
            #5

            Big thanks guys, next time i'll google better! Making the function static solved my problem. Thanks again for help guys!

            1 Reply Last reply
            0
            • Paul ColbyP Paul Colby

              One small thing to check: are you defining / declaring the sortFunc function before or after the qSort invocation? ie if the code you've shown above is all within one file, and in the order you've shown, then try moving the sortFunc function definition above the qSort call in the file.

              Cheers.

              Ivan NetskinI Offline
              Ivan NetskinI Offline
              Ivan Netskin
              wrote on last edited by
              #6

              @Paul-Colby said in Problem with qSort of QList<CustomType>:

              One small thing to check: are you defining / declaring the sortFunc function before or after the qSort invocation? ie if the code you've shown above is all within one file, and in the order you've shown, then try moving the sortFunc function definition above the qSort call in the file.

              Cheers.

              You were absolutely right. Thanks!

              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