Results 1 to 4 of 4

Thread: Subclassing QSqlTableModel to overwrite setQuery

  1. #1
    Join Date
    Nov 2007
    Posts
    17
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Subclassing QSqlTableModel to overwrite setQuery

    Hi folks

    I wonder why setQuery in QSqlTableModel is protected?
    I thought I need this feature, so I subclassed QSqlTableModel.

    Now, what you guys recommend: Subclass or no to subclass?
    Cause Qt had his reasons to made setQuery protected I think...

    Maybe I'm not as clever as I thought?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QSqlTableModel to overwrite setQuery

    It's protected, because QSqlTableModel is for selecting all columns from a single table, so you only have to supply the table name. You can customize parts of the query by calling or reimplementing certain methods, but if you want to have a full control over the query, use QSqlQueryModel.

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

    montuno (16th November 2007)

  4. #3
    Join Date
    Nov 2007
    Posts
    17
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Subclassing QSqlTableModel to overwrite setQuery

    selecting all columns of a single table doesn't usually meet our needs. IMHO QSqlTableModel is too restricted to a single case of use.

    But thanks jacek for your posting. I think I'm going to use QSqlQueryModel.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QSqlTableModel to overwrite setQuery

    You can always select rows from a view instead of a table.

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.