PDA

View Full Version : Question on subclassing QSqlTableModel



Doug Broadwell
12th February 2010, 01:06
It seems that subclassing QSqlTableModel would be a good way to set some columns as Editable and others not, by reimplementing QSqlTableModel::data to control Qt::EditRole (is this a good idea?). In looking at the source I see that most methods in QSqlTableModel start with a line that is either "Q_D(QSqlTableModel);" or "Q_D(const QSqlTableModel);"; some start with "Q_Q(QSqlTableModel);", some don't have such a thing.

I cannot find documentation on this. What are they? If I subclass QSqlTableModel do I need to include them in my reimplementations of methods? If I create a new method how do I determine if I need one of these?

Thanks

Doug Broadwell
12th February 2010, 01:46
Actually, I guess I need to reimplement "flags(const QModelIndex &index) const"

Doug Broadwell
12th February 2010, 22:44
Also - in methods involving the Editor and Editor Factory there is a class pointer variable "d", I cannot find out what this is and where it is initialized.

Lykurg
13th February 2010, 00:24
"d" and Q_D or Q_Q is all about pimpl. A good start in this topic you can find here: http://zchydem.enume.net/?p=504

norobro
13th February 2010, 01:12
I agree, the QSqlTableModel code is confusing.

There is a very good example in the docs (http://qt.nokia.com/doc/4.6/sql-querymodel.html) that goes about this the other way round: make columns of a read-only model (QSqlQueryModel) editable.

Also regarding your post on the newbie forum about delegates, the example demonstrates how to format columns by reimplementing "QSqlQueryModel::data ( const QModelIndex & item, int role = Qt:: DisplayRole ) const"