Results 1 to 4 of 4

Thread: multiple sort

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default multiple sort

    I have an QSqlQueryModel attached to QTableView and I would like to supprt multiple column sort meaning-- I would like to sort by column 1 then sort column 2 and so on

    e.g.
    unsorted table
    3 | C
    1 | B
    1 | K
    1 | A


    sorted table

    1 | A
    1 | B
    1 | C
    3 | C
    My table my contain millions of row

    Now, how can implement this , should i go and write a custom filter derived from QSortFilterProxy or I would go and parsed the sql statement of my model and and order by accordingly, (the latter seems to be tough) or next to impossible since my user will input the sql statement....

    I need your suggestion guys

    baray98

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: multiple sort

    The sql-parsing approach is not that hard (at least for simple queries without union etc).

    Apart from that, yes a custom QSortFilterProxyModel that uses several columns in QSortFilterProxyModel::lessThan() will work, too. (Just don't compare only the columns given in die indexes but the ones you are interested in)

    HTH

  3. #3
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: multiple sort

    The sql approach i think would be faster than QSortFilterProxy approach , mind you I have millions of row to sort right?

    I think in my sort I would try to sort them SQL style first then if I can't I will switch to QSortFilterProxyStyle

    any more ideas...

    baray98

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

    Default Re: multiple sort

    If you don't care about losing the selection and scrollbars position in the view then using the sql approach should be simpler but if you do care then you should use the proxy approach.
    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. Multiple project files in a single directory
    By jogeshwarakundi in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 17th July 2008, 08:03
  2. QTreeWidget (Row Check, Custom Sort)
    By AaronMK in forum Qt Programming
    Replies: 3
    Last Post: 8th January 2008, 16:55
  3. How to sort the treeWidget item according to size and date
    By santosh.kumar in forum Qt Programming
    Replies: 3
    Last Post: 23rd October 2007, 11:32
  4. How to sort a QComboBox in Qt4
    By guenthk in forum Qt Programming
    Replies: 7
    Last Post: 25th September 2006, 19:35
  5. how to corss compile for windows in Linux
    By safknw in forum Qt Programming
    Replies: 24
    Last Post: 13th May 2006, 06:23

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.