Results 1 to 4 of 4

Thread: QSqlTableModel::setQuery

  1. #1
    Join Date
    Sep 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QSqlTableModel::setQuery

    Hello, this is my first post to QtCentre.

    What's the proper handling for QSqlTableModel::setQuery()? My attempts return all rows extant in the db table. Yet the query (tested on the cmd-line) should have returned only a few rows.

    lastError() yields nothing.
    How does one get text from a model object's query() function?

    I have a situation where I need more control over the rows displayed from a QSqlRelationTableModel object than can be achieved with a "where" clause filter. The documentation states that setQuery() is normally not called directly on a model. Am I finding out why now?

    Thanks in advance!
    Scott

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

    Default Re: QSqlTableModel::setQuery

    try using QSqlQueryModel or call QSqlTableModel::setFilter(), only passing the where clause

  3. #3
    Join Date
    Sep 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSqlTableModel::setQuery

    Quote Originally Posted by caduel View Post
    try using QSqlQueryModel or call QSqlTableModel::setFilter(), only passing the where clause
    Thanks, but I don't think either will work for my purposes.

    I'm looking for a solution that provides read&write access to the table view (that nixes QSqlQueryModel). And I'd like to use an SQL query that joins more than just one table. I think that eliminates setFilter(). eg:

    SELECT foo.name FROM foo, bar WHERE foo_id = bar_id;

    I was hoping that I could pass a query like this to the table model's setQuery() method, "filtering" the records displayed in the table view and maintaining read&write access. My attempts so far are erroneously displaying all rows, rather than those that satisfy the where clause. (Note that my test query yields correct results from the cmd-line.)

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlTableModel::setQuery

    Could you achieve the filtering using a QSortFilterProxyModel on top of your QSqlTableModel ?

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.