QSort error

  • Hi,all.i'm want to use qsort to sort QStringList like "50% 60% 70%",and i write a function :

    bool compareItem(QString &first,QString &second)

    if(-1 == first.contains("%") || (-1 == second.contains("%")))
        return false;
    int num1 = 0,num2 = 0;
    num1 = first.remove(first.indexOf("%")).toInt();
    num2 = second.remove(second.indexOf("%")).toInt();
    return first < second;


    used it as

    but can't compiled with error:
    xxx:603: error: no matching function for call to 'qSort(QList<QString>::iterator, QList<QString>::iterator, <unresolved overloaded function type>)'
    /opt/qt-qvfb/include/QtCore/qalgorithms.h:184: note: candidates are: void qSort(RandomAccessIterator, RandomAccessIterator, LessThan) [with RandomAccessIterator = QList<QString>::iterator, LessThan = bool (xxxWidget::*)(QString&, QString&)]
    can someone help me ? Thanks a lot !

    [edit: added missing coding tags @ SGaist]

  • Hi,
    In my opinion method 'compareItem' should be static
    For example:
    @static bool compareItem(QString &first,QString &second)@

    It should work

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.