Results 1 to 3 of 3

Thread: Quick ? about qSort(Container & container)

  1. #1
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Quick ? about qSort(Container & container)

    My code looks something like this:
    Qt Code:
    1. QSet<QString> mySet;
    2. mySet.insert(someString);
    3. ...
    4. qSort(&mySet);
    To copy to clipboard, switch view to plain text mode 

    But I'm getting this error:
    'qSort' : cannot convert parameter 1 from 'QSet<T> *' to 'QSet<T> & ' with [T=QString] and [T=QString]

    I think my logic/syntax is okay, so what is the problem?

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

    Default Re: Quick ? about qSort(Container & container)

    qSort takes a reference to the container, not a pointer. So the correct call is:
    Qt Code:
    1. qSort(mySet);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Quick ? about qSort(Container & container)

    You can't sort a QSet. use QMap<QString, bool> and the keys will be sorted on insertion. Or retrieve the keys and sort them:
    Qt Code:
    1. QSet<QString> mySet;
    2. ...
    3. QList<QString> values = mySet.values();
    4. qSort(values);
    To copy to clipboard, switch view to plain text mode 

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.