Results 1 to 4 of 4

Thread: how to limit sql rows

  1. #1
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default how to limit sql rows

    Hi,
    Anyone knows how to limit number of rows shown in QTreeView with QSqlTableModel (or QSortFilterProxy) to some number (given by user)?
    You have to run a level 3 diagnostic.

    Ashes to ashes, Qt to Qt ( wysota )

  2. #2
    Join Date
    Dec 2007
    Posts
    129
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to limit sql rows

    Quote Originally Posted by calhal View Post
    Hi,
    Anyone knows how to limit number of rows shown in QTreeView with QSqlTableModel (or QSortFilterProxy) to some number (given by user)?
    in my case im adding LIMIT to setfilter()
    note: you cannot directly add LIMIT to filter like setfileter("LIMIT 10"), adding Where clause will do the trick setfilter("Where yourdata not null LIMIT 10")..

    thats my quick solution.

  3. #3
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to limit sql rows

    Thanks for your response. But it doesn't work for me. I get no rows at all when I add LIMIT to the filter.
    You have to run a level 3 diagnostic.

    Ashes to ashes, Qt to Qt ( wysota )

  4. #4
    Join Date
    Dec 2009
    Location
    Austria
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to limit sql rows

    Hi all!

    I think this happens because QSqlTableModel will call setSort after setFilter and this produces an Error (the LIMIT clause must be after any sorting clauses).

    As far as I know, the only solutions are:

    • Use QSqlQueryModel
    • Subclass QSqlTableModel and implement the function (e.g implement the setQuery function)


    I hope this can help.

Similar Threads

  1. QSqlTableModel inserts empty rows
    By Nesbitt in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2008, 13:47
  2. Removing rows
    By indifference in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2007, 17:54
  3. Replies: 1
    Last Post: 28th September 2006, 07:21

Tags for this Thread

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.