Results 1 to 13 of 13

Thread: Bug in QStringList custom sort

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2013
    Posts
    71
    Platforms
    Windows
    Thanks
    6
    Thanked 3 Times in 3 Posts

    Default Bug in QStringList custom sort

    Qt Code:
    1. QStringList listNames;
    2. QStringList tempList;
    3. listNames << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
    4. list << "Jan" << "Mar" << "May" << "Jul" << "Sep" << "Nov" << "Feb" << "Apr" << "Jun" << "Aug" << "Oct" << "Dec" << "Jan" << "Mar" << "May" << "Jul" << "Sep" << "Nov" << "Feb" << "Apr" << "Jun" << "Aug" << "Oct" << "Dec" << "Jan" << "Mar" << "May" << "Jul" << "Sep" << "Nov" << "Feb" << "Apr" << "Jun" << "Aug" << "Oct" << "Dec";
    5. int startSize = list.size();
    6. int num;
    7. for(int i = 0; i<startSize; i++){
    8. for(int j = 0; j<listNames.size(); j++){
    9. if(list.contains(listNames[j],Qt::CaseInsensitive)){
    10. num = list.indexOf(listNames[j]);
    11. //cout << num << endl;
    12. }
    13. }
    14. tempList << list[num];
    15. list.removeAt(num);
    16. }
    17. for(int i = 0; i<startSize; i++){
    18. list << tempList[tempList.size()-1];
    19. tempList.removeLast();
    20. }
    21.  
    22.  
    23. for(int i = 0; i<list.size(); i++){
    24. cout << list[i].toStdString() << endl;
    25. }
    To copy to clipboard, switch view to plain text mode 
    in this example the user input would be the QStringList list and the order they are being sorted is QStringList listNames
    it works perctly if the user inputs the same exact as the sorting order.

    but what I would like to do is if the user inputs "jan" it will know it is the same as "Jan" I can check to see if it is the same by using contains which will yeah find it...but
    when I do the index of it I will always get -1 because I can not think of a way to do
    Qt Code:
    1. indexOf(QString, Qt::CaseInsensitive)
    To copy to clipboard, switch view to plain text mode 
    is this even possible?

    EDIT: well I can think of one way but I would prefer not to do it.
    it would be to use QString::toUpper or QString::toLower for both of the QStringLists and it wouldnt matter what they input.
    but the problem with that is.....I want the end result to be first letter Uppercase rest of the letters Lowercase

  2. #2
    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: Bug in QStringList custom sort

    So is your question about sorting or searching?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Custom widget table sort
    By giantdragon in forum Qt Programming
    Replies: 10
    Last Post: 10th June 2011, 12:36
  2. Custom Item Delegate Reset, sort of.
    By waynew in forum Qt Programming
    Replies: 3
    Last Post: 1st September 2010, 22:48
  3. QTableWidget custom sort
    By mattc in forum Qt Programming
    Replies: 1
    Last Post: 24th August 2010, 11:01
  4. QTreeWidget (Row Check, Custom Sort)
    By AaronMK in forum Qt Programming
    Replies: 3
    Last Post: 8th January 2008, 15:55
  5. Custom sort with QTableWidget
    By nicolas44 in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2007, 00:47

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.