[Qt-interest] Multiple QSqlTableModel instances for the same table

Petric Frank pfrank at gmx.de
Tue Jul 20 17:59:24 CEST 2010


Hello,

On Monday, 19. July 2010 23:34:13 Noah wrote:
> Petric Frank wrote:
> > Hello,
> > 
> > i have a question. If i do at different locations (given default
> > connection is established to a database) in the same application:
> > 
> > Location 1:
> > 
> > QSqlTableModel * model_1 = new QSqlTableModel (this);
> > model_1->setTable ("TestTable");
model_1->select ();
> > 
> > 
> > Location 2:
> > 
> > QSqlTableModel * model_2 = new QSqlTableModel (this);
> > model_2->setTable ("TestTable");
model_2->select ();
> > 
> > model_2->setData (.....)
> > 
> > 
> > Does model_1 recognize that the data of the table he is assigned to have
> > been updated ?
> > 
> > EditStrategy is set to OnFieldChange on both instances.
> > 
> > regards
> > 
> >   Petric
> 
> No, model_1's data will only get populated when you explicitly call
> Select() or a related function or after a commit.

Ok, i forgot it to write here. For sure the select call was executed after 
assigning the table name at both model setups.
 
> You could have your database emit a notification when that table is
> updated, use QSqlDriver::subscribeToNotification() to catch it, and then
> connect the notification signal to a slot that calls model_1->select().
> QSqlTableModel definitely doesn't automatically update in real time though.

For example MySQL or Oracle does not support this feature. So this 
registration does not have any effect.

Is there a signal a QSqlDatabase or QSql(Relational)TableModel emits which can 
be used for that ?
I do not talk about dataChanged signal. This is (to my knowledge) emitted when 
the in-memory copy is updated - not when the data is really written to the 
database. Only in this case model_1 is able to read the changed data.

regards
  Petric



More information about the Qt-interest-old mailing list