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.
  • I Offline
    I Offline
    Ivan Netskin
    wrote on 30 Nov 2016, 15:53 last edited by Ivan Netskin 12 Jan 2016, 08:16
    #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!

    K 1 Reply Last reply 30 Nov 2016, 21:11
    0
    • M Offline
      M Offline
      m.sue
      wrote on 30 Nov 2016, 16:06 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
      • P Offline
        P Offline
        Paul Colby
        wrote on 30 Nov 2016, 20:47 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.

        I 1 Reply Last reply 1 Dec 2016, 08:55
        2
        • I Ivan Netskin
          30 Nov 2016, 15:53

          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!

          K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 30 Nov 2016, 21:11 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
          • I Offline
            I Offline
            Ivan Netskin
            wrote on 1 Dec 2016, 08:14 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
            • P Paul Colby
              30 Nov 2016, 20:47

              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.

              I Offline
              I Offline
              Ivan Netskin
              wrote on 1 Dec 2016, 08:55 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

              1/6

              30 Nov 2016, 15:53

              • Login

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