Results 1 to 7 of 7

Thread: [Qt4] QSORT

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Posts
    4

    Default [Qt4] QSORT

    Hi, I've got a problem using qSort, when I reimplement LessThan :

    In my Vertical class:
    Qt Code:
    1. QList<Plane *> Vertical::planes; //static list of Plane objects
    2.  
    3. bool lessThan( const Plane *plane1, const Plane *plane2)
    4. {
    5. Plane *me = Vertical::getPlanes().at(0);
    6. return(plane1->close(me->getPosition()) < plane2->close(me->getPosition()));
    7. }
    8.  
    9.  
    10. void Vertical::sortL(const QString &str)
    11. {
    12. QList <Plane *> list;
    13. qCopy(planes.begin()+1, planes.end(), list.begin());
    14. qSort(list.begin(), list.end(),lessThan);
    15. .......
    16. }
    17.  
    18. QList<Plane *> Vertical::getPlanes() {
    19. return planes;
    20. }
    21.  
    22.  
    23. and in the Plane class :
    24.  
    25. double Plane::close(const QPoint &p) const
    26. {
    27. return (sqrt((double)((p.x()-position.x())^2 + (p.y()-position.y())^2)));
    28. }
    To copy to clipboard, switch view to plain text mode 
    And the compiler says that qsort does not look as a function that takes 2 arguments, and gives me some lines number erros in qalgorithms.h
    Any ideas ???

  2. #2
    Join Date
    May 2006
    Posts
    55
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [Qt4] QSORT

    qStableSort, may be ?

  3. #3
    Join Date
    May 2006
    Posts
    4

    Default Re: [Qt4] QSORT

    no, I ve got the same problem, but thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Qt4] QSORT

    Quote Originally Posted by jane
    And the compiler says that qsort does not look as a function that takes 2 arguments, and gives me some lines number erros in qalgorithms.h
    Could you post the exact error message?

  5. #5
    Join Date
    May 2006
    Posts
    4

    Default Re: [Qt4] QSORT

    Ok no problem, but as I m french, it s not in english, here it is :

    c:\Qt\src\corelib\tools\qalgorithms.h(341): error C2064: le terme ne correspond pas à une fonction qui prend les arguments 2

    which means the term does not match with a function which takes the arguments 2
    the line in qalgorithms.h :
    if (!lessThan(*hi, *lo)) {
    Last edited by jane; 24th May 2006 at 14:33.

  6. #6
    Join Date
    May 2006
    Posts
    4

    Default Re: [Qt4] QSORT

    Ok,
    problem solved :
    I have no idea why but I tried turning the lessThan function static and now it works ???!!!! which I don t really understands but it do compile, so ....

  7. #7
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: [Qt4] QSORT

    qSort cannot take a member function pointer as an argument, which is a very different type than regular function pointers. Your function is really defined as:
    bool Vertical::lessThan( const Plane *plane1, const Plane *plane2)

    I think this article might explain it better:
    http://www.informit.com/guides/conte...lus&seqNum=142
    Last edited by gfunk; 24th May 2006 at 23:47.
    Software Engineer



Similar Threads

  1. Static Compile [Qt4]
    By PieaholicX in forum Newbie
    Replies: 11
    Last Post: 1st September 2006, 17:18
  2. [qt4] Task Bar Type Behavior Wanted
    By KMAPSRULE in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2006, 20:12
  3. [QT4] QThread and printing a QList<QPixmap>
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 21:44
  4. [QT4] QTreeView, QAbstractItemModel and sorting
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th March 2006, 20:16
  5. [QT4] QListWidget:: setItemSelected misbehaving?
    By KShots in forum Qt Programming
    Replies: 2
    Last Post: 21st March 2006, 14:07

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.