How to refresh view when model data changes
-
wrote on 22 Oct 2013, 18:18 last edited by
Hello,
i have a problem with Qtableview witch is considered like a view , and my model ( QsqlqueryModel )
i have manipulate data in the model ( delete , add , ....etc ) , but the view not updating in real time
i want a better way to informe the view with updating of model data
-
wrote on 23 Oct 2013, 19:31 last edited by
any one knows how we can do this ??
-
wrote on 23 Oct 2013, 19:39 last edited by
Hi,
I'm not sure it will help, but maybe you can call update() on your QTreeView when your data change.
-
wrote on 24 Oct 2013, 05:50 last edited by
QSqlQueryModel is read-only. Maybe you need QSqlTableModel instead.
-
wrote on 24 Oct 2013, 08:30 last edited by
[quote author="chris17" date="1382593819"]QSqlQueryModel is read-only. Maybe you need QSqlTableModel instead.[/quote]
i don't want to allow users , to be able to edit cells , i need it read it only,
my problem is when other events make changes in database , and this changes affecte the my model , so, i need to update it immediatly
-
wrote on 24 Oct 2013, 10:15 last edited by
Hi,
There are two ways of doing this. (when you read the documents you should have thought of this yourself).
This first one is the update() function of the QAbstractItemView which QTableView inherits. The second is the reset function of the QAbstractItemView.
The big difference is that the update gets an index of the positions in the table to refresh. The view does a complete rebuild, also loosing any selection behavior etc.
Greetz -
wrote on 24 Oct 2013, 16:54 last edited by
i have tried the two function but , they not work for me , the model still need to query the database again to be refresh
her is my code
@ connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),ui->tableView,SLOT(reset()));
connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),ui->tableView,SLOT(update()));@
1/7