Results 1 to 4 of 4

Thread: Some trouble with QList<> and qsort

  1. #1
    Join Date
    Jul 2014
    Posts
    17
    Thanks
    1

    Default Re: Some trouble with QList<> and qsort

    I hope somebody can help. I try to sort, but I get an error. :-(((


    Qt Code:
    1. class FileEntry
    2. {
    3.  
    4. public:
    5. QString name;
    6. QString absolutePath;
    7. QString relativePath;
    8. double size;
    9. QString typ;
    10. QDateTime createDate;
    11. bool selected;
    12. int index;
    13.  
    14.  
    15. FileEntry(QString pName, QString pAbsolutePath,QString pRelativePath,double pSize,QString pTyp,QDateTime pCreateDate,bool pSelected,int pIndex)
    16. {
    17. name = pName;
    18. absolutePath =pAbsolutePath;
    19. relativePath=pRelativePath;
    20. size=pSize;
    21. typ=pTyp;
    22. createDate=pCreateDate;
    23. selected=pSelected;
    24. index = pIndex;
    25. }
    26.  
    27. };
    28.  
    29.  
    30.  
    31. bool lessSize(const FileEntry& a, const FileEntry& b)
    32. {
    33. return a.size < b.size;
    34. }
    35.  
    36.  
    37.  
    38.  
    39. void DoSelection()
    40. {
    41. QList<FileEntry> tmpList;
    42.  
    43. tmpList.append(FileEntry("A","A","A",2.2,"A",QDateTime(),false,1));
    44. tmpList.append(FileEntry("A","A","A",2.2,"A",QDateTime(),false,1));
    45.  
    46. qsort(tmpList.begin(),tmpList.end(),lessSize);
    47. }
    To copy to clipboard, switch view to plain text mode 



    I get these error:
    error: cannot convert 'QList<FileEntry>::iterator' to 'void*' for argument '1' to 'void qsort(void*, size_t, size_t, __compar_fn_t)'
    qsort(tmpList.begin(),tmpList.end(),lessSize);

    Thx.Cit

    I tried the way from this post.....

    http://www.qtcentre.org/threads/9485...tains-POINTERS

  2. #2
    Join Date
    Oct 2013
    Posts
    41
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Some trouble with QList<> and qsort

    having never used qsort before, all I can say is that its looking at the wrong footprint of qsort. What version of Qt are you running?

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Some trouble with QList<> and qsort

    this
    Qt Code:
    1. qsort(tmpList.begin(),tmpList.end(),lessSize);
    To copy to clipboard, switch view to plain text mode 
    tries to call C function
    Qt Code:
    1. qsort(void* ptr, size_t count, size_t size_in_bytes, int (*compare_function)(const void*,const void*))
    To copy to clipboard, switch view to plain text mode 
    signature obviously does not match arguments provided.
    Probably this is what you want
    Qt Code:
    1. qSort(tmpList.begin(),tmpList.end(),lessSize);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jul 2014
    Posts
    17
    Thanks
    1

    Default Re: Some trouble with QList<> and qsort

    I go back to the simple basic's std:sort() instead of qsort()...... and it works from the beginning-

Similar Threads

  1. Sorting using qSort(), - if QList contains POINTERS
    By joseph in forum Qt Programming
    Replies: 13
    Last Post: 18th August 2013, 19:55
  2. How to qSort a QList of a class
    By TempleClause in forum Newbie
    Replies: 5
    Last Post: 14th October 2012, 23:50
  3. sorting static QList<MyClass> list with qSort
    By oruccim in forum Qt Programming
    Replies: 3
    Last Post: 15th December 2010, 17:13
  4. How to qSort a Qlist of QPair?
    By Trader in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2010, 20:04
  5. why doesn't qSort work when a QList hosts a pointertype?
    By momesana in forum Qt Programming
    Replies: 1
    Last Post: 4th October 2009, 05:28

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.