Results 1 to 5 of 5

Thread: Question on subclassing QSqlTableModel

  1. #1
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Question on subclassing QSqlTableModel

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Question on subclassing QSqlTableModel

    Actually, I guess I need to reimplement "flags(const QModelIndex &index) const"

  3. #3
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Question on subclassing QSqlTableModel

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Question on subclassing QSqlTableModel

    "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

  5. The following 2 users say thank you to Lykurg for this useful post:

    dougbroadwell (15th February 2010), norobro (13th February 2010)

  6. #5
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Question on subclassing QSqlTableModel

    I agree, the QSqlTableModel code is confusing.

    There is a very good example in the docs 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"

Similar Threads

  1. QSqlTableModel and QSqlTableView question
    By waynew in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2009, 01:06
  2. Question about subclassing QStyledItemDelegate
    By dpimka in forum Qt Programming
    Replies: 4
    Last Post: 10th July 2009, 18:09
  3. Replies: 2
    Last Post: 14th February 2008, 21:06
  4. Subclassing QSqlTableModel to overwrite setQuery
    By montuno in forum Qt Programming
    Replies: 3
    Last Post: 16th November 2007, 11:32
  5. Access to QSqlTableModel::isDirty Question.
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2007, 18:49

Tags for this Thread

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.