Results 1 to 4 of 4

Thread: Sorting QPolygonF

  1. #1
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Sorting QPolygonF

    there is a way to sort a QPolygonF, for example, by considering
    the x value?
    Regards

  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: Sorting QPolygonF

    May be you can put the polygons in QList. Then use qSort .
    You can provide your own lessThan function in the qSort. See docs for more info

  3. #3
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorting QPolygonF

    I tried with the following code

    Qt Code:
    1. bool MyPlot::lessThanPoint(const QPointF &p1, const QPointF &p2)
    2. {
    3. return ( p1.x() < p2.x() );
    4.  
    5. }
    6. QPolygonF MyPlot::combine(const QPolygonF &p1, const QPolygonF &p2)
    7. {
    8.  
    9.  
    10.  
    11.  
    12. QPolygonF un(p1.united(p2));
    13. qSort(un.begin(),un.end(),lessThanPoint);
    14. return un;
    15. }
    To copy to clipboard, switch view to plain text mode 

    but I get

    myplot.cpp:943: error: no matching function for call to ‘qSort(QPointF*, QPointF*, <unresolved overloaded function type>)’
    /usr/local/Trolltech/Qt-4.4.0/include/QtCore/qalgorithms.h:203: note: candidates are: void qSort(RandomAccessIterator, RandomAccessIterator, LessThan) [with RandomAccessIterator = QPointF*, LessThan = bool (MyPlot::*)(const QPointF&, const QPointF&)]


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

    Default Re: Sorting QPolygonF

    You can't use member functions for such functors.

    You have to make that lessThanPoint either
    * static (in your class)
    * static (in your file; remove from class header then)
    * turn it into a functor (i.e. a real class; or by means like boost::bind)

    HTH

  5. The following user says thank you to caduel for this useful post:

    giusepped (7th January 2009)

Similar Threads

  1. Refresh QTableView after sorting
    By araglin in forum Newbie
    Replies: 4
    Last Post: 18th December 2008, 22:13
  2. Qt4: Sorting QAbstractItemVew inherited view
    By nando in forum Qt Programming
    Replies: 3
    Last Post: 12th February 2008, 18:30
  3. Column Sorting
    By sumsin in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2006, 07:48
  4. QT4: Sorting in QTreeWidget (subclass)
    By Michiel in forum Qt Programming
    Replies: 21
    Last Post: 29th March 2006, 18:08
  5. [QT4] QTreeView, QAbstractItemModel and sorting
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th March 2006, 20:16

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.