Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSort error
Qt 6.11 is out! See what's new in the release blog

QSort error

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    freebigfish
    wrote on last edited by
    #1

    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
    @
    qSort(beforeSort.begin(),beforeSort.end(),compareItem),
    @

    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]

    1 Reply Last reply
    0
    • I Offline
      I Offline
      Ildar
      wrote on last edited by
      #2

      Please, using code tag for your code.
      qSort is "absolute":http://qt-project.org/doc/qt-5/qtalgorithms-obsolete.html#qSort, try "sort":http://www.cplusplus.com/reference/algorithm/sort/?kw=sort

      1 Reply Last reply
      0
      • T Offline
        T Offline
        turaz
        wrote on last edited by
        #3

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

        It should work

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved