View Full Version : Sorting QPolygonF
giusepped
7th January 2009, 03:46
there is a way to sort a QPolygonF, for example, by considering
the x value?
Regards
aamer4yu
7th January 2009, 07:23
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
giusepped
7th January 2009, 08:18
I tried with the following code
bool MyPlot::lessThanPoint(const QPointF &p1, const QPointF &p2)
{
return ( p1.x() < p2.x() );
}
QPolygonF MyPlot::combine(const QPolygonF &p1, const QPolygonF &p2)
{
QPolygonF un(p1.united(p2));
qSort(un.begin(),un.end(),lessThanPoint);
return un;
}
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&)]
caduel
7th January 2009, 08:34
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
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.