Results 1 to 2 of 2

Thread: QSqlTableModel and QTableView and sorting

  1. #1
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSqlTableModel and QTableView and sorting

    Hello,

    I have setSortingEnabled (true) for this table so that when I click on a column header, the table gets sorted to that column. Very nice.

    But in combination with setFilter() the sorting order is not always the same. The order of records is different if a filter is applied.

    There are columns with the same value, and in a normal sql case you would then use an 'order by' with 2 arguments, 'order by thisfirst, thatsecond' which would get around such problems. I suspect this is the reason why the order differs when I set a filter.

    Trying to illustrate:

    Name Type Age (sorted on column Age)
    a 1 1
    b 1 1
    c 2 1

    setFilter(type = 1)

    b 1 1
    a 1 1

    Should be a first, then b.

    Hope I am being a bit clear. Thanks.
    Last edited by JeanC; 4th April 2008 at 19:27.

  2. #2
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlTableModel and QTableView and sorting

    It looks like there is no easy solution to this.
    Just as sortByColumn() only accepts 1 column (as opposed to 'order by one,two').

    A workaround is to have all fields in the column that you want to sort on have
    unique values, this way if you setFilter() the sortorder is the same as without filter.
    Of course this is not alwaws desirable or possible.

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.