Results 1 to 5 of 5

Thread: qSort with lessThan

  1. #1
    Join Date
    Jan 2006
    Location
    germany
    Posts
    75
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default qSort with lessThan

    Hi everyone!

    I want to do custom sorting with a QList (its a list of pointers so the sorting has to be custom...)

    I followed the doc and wrote:
    Qt Code:
    1. bool QBsdPortGlobal::lessThan(QBsdPort* p1, QBsdPort* p2);
    2. {
    3. return p1->origin() < p2->origin();
    4. }
    To copy to clipboard, switch view to plain text mode 
    but whenver I call
    Qt Code:
    1. qSort(m_collection.begin(),
    2. m_collection.end(),
    3. lessThan);
    To copy to clipboard, switch view to plain text mode 
    I get:
    Qt Code:
    1. bsdportglobal.cpp:497: error: no matching function for call to 'qSort(QList<QBsdPort*>::iterator, QList<QBsdPort*>::iterator, <unresolved overloaded function type>)'
    2. /usr/local/include/qt4/QtCore/qalgorithms.h:203: note: candidates are: void qSort(RandomAccessIterator, RandomAccessIterator, LessThan) [with RandomAccessIterator = QList<QBsdPort*>::iterator, LessThan = bool (QBsdPortGlobal::*)(QBsdPort*, QBsdPort*)]
    To copy to clipboard, switch view to plain text mode 
    Why is lessThan() unresovled? I put it in the source and it is declared in the header. The fcuntion works otherwise...

    Thanks for your help!
    Quote Originally Posted by Bertolt Brecht
    What is the robbing of a bank compared to the founding of a bank?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qSort with lessThan

    Where are you calling the function qSort from ?
    lessThan seems to be a member function of QBsdPortGlobal. So if are calling qSort outside the class, u must be getting error.
    Hope am not wrong

  3. #3
    Join Date
    Jan 2006
    Location
    germany
    Posts
    75
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: qSort with lessThan

    Thanks for the reply.

    I only call qSort from other member-functions of QBsdPort::global...
    Quote Originally Posted by Bertolt Brecht
    What is the robbing of a bank compared to the founding of a bank?

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qSort with lessThan

    You can not use a member function (needs an object to be called upon).

    You can:
    * make your function static
    * make a plain function (outside of a class)
    * make a regular function object
    * use something like Boost.Bind

    HTH

  5. The following 2 users say thank you to caduel for this useful post:

    Ishmael (26th September 2010), soul_rebel (19th August 2008)

  6. #5
    Join Date
    Jan 2006
    Location
    germany
    Posts
    75
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: qSort with lessThan

    Thanks, I made it static.
    Quote Originally Posted by Bertolt Brecht
    What is the robbing of a bank compared to the founding of a bank?

Similar Threads

  1. Sorting using qSort(), - if QList contains POINTERS
    By joseph in forum Qt Programming
    Replies: 13
    Last Post: 18th August 2013, 18:55
  2. QSortFilterProxyModel - lessThan sorts wrong column
    By ghorwin in forum Qt Programming
    Replies: 2
    Last Post: 21st July 2008, 09:06
  3. qSort() problem
    By darksaga in forum Qt Programming
    Replies: 5
    Last Post: 17th August 2007, 11:47
  4. qSort doesn't work with member function
    By ber_44 in forum Qt Programming
    Replies: 10
    Last Post: 2nd June 2007, 12:00
  5. [Qt4] QSORT
    By jane in forum Qt Programming
    Replies: 6
    Last Post: 24th May 2006, 23:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.