Results 1 to 3 of 3

Thread: Trouble with sql views and sorting

  1. #1
    Join Date
    Feb 2008
    Posts
    79
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Trouble with sql views and sorting

    Inside QTableView I want to show data from Sql view that fetches data from multiple tables.
    I tried two approaches, but both have their own problems:

    1. First approach: I used QSqlQueryModel in combination with QTableView. Data are shown OK, but sorting is not implemented in QSqlQueryModel, so that sorting inside QTableView does not work even if it is enabled with sortingEnabled()

    2. Second approach: I tried to use QSqlTableModel in combination with QTableView. I think that sorting should work now, but there is no data shown. It is really strange, because data are shown if I fetch it from SQL table, but if I use SQL view, then data are not shown. I thought that for Qt it does not matter if it fetches data from table or from view.

    Any idea how to get data from view AND have sorting enabled?

  2. #2
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Trouble with sql views and sorting

    Hi Tiansen, I think you need a proxy model. The easiest solution might be using QSortFilterProxyModel and keep your QSqlQueryModel instance as the source model.
    ~ We are nothing in this universe ~

  3. The following user says thank you to viulskiez for this useful post:

    Tiansen (14th February 2014)

  4. #3
    Join Date
    Feb 2008
    Posts
    79
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Trouble with sql views and sorting

    Very good, thank you for that tip.

Similar Threads

  1. Hi all, some about lists and views
    By kosasker in forum Newbie
    Replies: 4
    Last Post: 24th January 2011, 13:55
  2. how implement different views
    By Sunny31 in forum Qt Quick
    Replies: 3
    Last Post: 29th December 2010, 16:17
  3. DB changes not updating in views
    By Jeffb in forum Newbie
    Replies: 11
    Last Post: 11th May 2010, 11:00
  4. Model with two very different views
    By mholmes in forum Qt Programming
    Replies: 3
    Last Post: 8th April 2010, 00:19
  5. QAbstractItemModel to different views
    By ganeshshenoy in forum Qt Programming
    Replies: 3
    Last Post: 19th February 2008, 14:43

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.