View Full Version : Subclassing QSqlTableModel to overwrite setQuery

15th November 2007, 17:45
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? :o

15th November 2007, 22:54
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.

16th November 2007, 08:35
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.

16th November 2007, 11:32
You can always select rows from a view instead of a table.