[Qt-interest] Using qSort with lists of QPointers
Ellen Kestrel
dragonflykes at gmail.com
Mon Sep 6 02:11:41 CEST 2010
Thanks - that solved it. I thought it could just use the instance that it
was called from, but I guess it doesn't have any way of accessing that
object.
EK
On Sun, Sep 5, 2010 at 5:37 PM, Rohan McGovern <rohan.mcgovern at nokia.com>wrote:
> Ellen Kestrel said:
> > I'm trying to use qSort to sort a list of QPointers to a class (which
> subclasses QObject). There is a public lessThan function actually within
> the class itself, and when I was sorting the list by hand I simply called it
> from the class that manages the list. Since I want to use qSort in the
> list-managing class, I defined a member function in that class with only
> this line of code:
> >
> > bool ListManager::objPrecedes (QPointer<MyClass> c1, QPointer<MyClass>
> c2) {
> > return c1->comesBefore (c2);
> > }
> >
> > and tried calling qSort as
> >
> > qSort (list.begin (), list.end (), objPrecedes);
> >
> > but this gives me a compiler error:
> >
> > error: no matching function for call to ‘qSort(QList<QPointer<MyClass>
> >::iterator, QList<QPointer<MyClass> >::iterator, <unresolved overloaded
> function type>)’
> > /usr/include/qt4/QtCore/qalgorithms.h:184: note: candidates are: void
> qSort(RandomAccessIterator, RandomAccessIterator, LessThan) [with
> RandomAccessIterator = QList<QPointer<MyClass> >::iterator, LessThan = bool
> (ListManager::*)(QPointer<MyClass>, QPointer<MyClass>)]
>
> objPrecedes should be a static function. At the moment you've made it a
> member function; that means there's a hidden third parameter which needs
> to be passed to each call of the function - the value of `this' -
> and qSort wants a function which takes only two parameters.
> --
> Rohan McGovern
> QA Engineer
> Qt Development Frameworks, Nokia
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100905/7ab35cf8/attachment.html
More information about the Qt-interest-old
mailing list