PDA

View Full Version : Subclassing QSqlTableModel to overwrite setQuery



montuno
15th November 2007, 16: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

jacek
15th November 2007, 21: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.

montuno
16th November 2007, 07: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.

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