Results 1 to 6 of 6

Thread: Sorting a QList containing structured datas

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Sorting a QList containing structured datas

    Hi everybody,

    I am sorry for posting what is probably a stupid question but I failed to find by myself the answer... sorting a Qlist with qSort() is tricky when the list only contains a single variable. But using a structure, it failed since the qSort() algorithm did not knows which field in the structure is to be sorted. Here is my code :

    Qt Code:
    1. struct myData{
    2. QString namefile;
    3. int filesize;
    4. };
    5.  
    6. QList <myData> list;
    7. populatelist();
    8. ...
    To copy to clipboard, switch view to plain text mode 

    now how to sort list by namefile or filesize ?
    I presume I need some pointers, but as newbie, I turn around it unsuccessfully. Thank you for any help.
    Last edited by jpn; 17th December 2008 at 19:05. Reason: missing [code] tags

Similar Threads

  1. Sorting using qSort(), - if QList contains POINTERS
    By joseph in forum Qt Programming
    Replies: 13
    Last Post: 18th August 2013, 18:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.