Results 1 to 20 of 22

Thread: Sorting a QVector

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: Sorting a QVector

    Quote Originally Posted by wysota View Post
    Actually qSwap doesn't use memcpy directly (4.3 beta):
    Weird enough. It must have remained a beta .
    I can't really find this implementation anywhere in 4.3.0 ( not beta ).

    I even made small test and stepped in qSwap. The one I posted above is used for all types.

    EDIT:
    I think those casts only switch the base addresses of the variables without actually swapping any memory or calling =() operators.

    Regards
    Last edited by marcel; 11th August 2007 at 12:23.

  2. #2
    Join Date
    Jul 2007
    Posts
    39
    Thanks
    10

    Default Re: Sorting a QVector

    Hi all

    I am trying to sort a QList. I am using a custom type with overloaded < operator but then to check out the source of error, I changed the list to a interger one.

    My code now is just this:
    QList<int> list;
    list << 10 << 5 << 4;
    qsort(list.begin(), list.end());
    I am getting the following error.
    Cannot convert QList<int>::iterator to void* argument for '1' to 'void qsort(void* ,size_t, size_t, int (*) (const void*, const void*))'
    Can anyone suggest what would be the possible error?

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: Sorting a QVector

    It is qSort, with capital "S".

    Or, if not, try:
    Qt Code:
    1. qSort(list.begin(), list.end(), qLess<int>());
    To copy to clipboard, switch view to plain text mode 

    Regards

  4. The following user says thank you to marcel for this useful post:

    arjunasd (11th August 2007)

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Sorting a QVector

    You can also simply call "qSort(list)" if you want to sort the whole list.

Similar Threads

  1. Model sorting vs. selection
    By VlJE in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2006, 17:46
  2. QVector problem
    By kingslee in forum Qt Programming
    Replies: 5
    Last Post: 19th October 2006, 11:42
  3. Column Sorting
    By sumsin in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2006, 08:48
  4. QT4: Sorting in QTreeWidget (subclass)
    By Michiel in forum Qt Programming
    Replies: 21
    Last Post: 29th March 2006, 19:08
  5. [QT4] QTreeView, QAbstractItemModel and sorting
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th March 2006, 21:16

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.