Important: Please read the Qt Code of Conduct -

[SOLVED] std::sort on QList<QPushButton*> doesn't work

  • My code is the following:

    I have declare

    @QList<QPushButton*> *local; @

    and I use it in the following mode:

    @std::sort(local->begin(), local->end(), pushButtonLessThan );@

    and after I declare:

    @bool MainWindow::pushButtonLessThan(QPushButton v1, QPushButton v2)
    QRect myrect1;
    QRect myrect2;

    myrect1 = v1.geometry();
    myrect2 = v2.geometry();
    if (myrect1.left() < myrect2.left()) return true;
    else return false;


    When I compile I have the following error:

    @........\android\androidNDK\sources\cxx-stl\gnu-libstdc++\4.8\include/bits/stl_algo.h:5474:5: note: void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = QList<QPushButton*>::iterator; _Compare = bool (MainWindow::)(QPushButton, QPushButton)]
    sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
    ........\android\androidNDK\sources\cxx-stl\gnu-libstdc++\4.8\include/bits/stl_algo.h:5474:5: note: no known conversion for argument 3 from '<unresolved overloaded function type>' to 'bool (MainWindow::
    )(QPushButton, QPushButton)'@

    Where is the problem ?

    Please can you help me?

  • Moderators

    You need the method to be static, and you have to make it accept QPushButton pointers. Right now you are trying to sort a list of pointers using a sorting function that does not take in pointers.

  • Thanks, now it work.

Log in to reply