[Qt-interest] Multiple QSqlTableModel instances for the same table
Noah
noah at pcc.com
Mon Jul 19 23:34:13 CEST 2010
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");
>
>
> Location 2:
>
> QSqlTableModel * model_2 = new QSqlTableModel (this);
> model_2->setTable ("TestTable");
>
> 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.
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.
- Noah
More information about the Qt-interest-old
mailing list