PDA

View Full Version : How to auto update values on QTableView?



vrltwe
28th December 2013, 17:22
For the purpose of visualizing data from a MySQL table, a QTableView is being used in conjunction with a QSqlTableModel. How can I auto update the QTableView as new values are inserted in the database?

Thanks in advance.

wysota
29th December 2013, 19:38
You need to be notified about changes to the database and rerun the select statement. If your database does not support notifications or your data feeder does not support notifications then you need to implement such system yourself external to the database.

vrltwe
30th December 2013, 17:09
MySQL 5.5.24 (WAMP 2.2) is being used. Could you please provide some details on how this can be done?

Thanks in advance.

ChrisW67
30th December 2013, 20:19
AFAICT there is no inbuilt Mysql mechanism to alert an external observer that a table has changed. You can use a trigger to detect updates but to notify an external watcher you would need to use a user-defined function (UDF) to call an external application that broadcasts the notification. Here is an example
https://help.pubnub.com/entries/22449603-Can-I-Push-a-Message-via-a-Database-Trigger-
(This will not scale well for high speed inserts)

You can also use a trigger to update a single row table containing a timestamp that your program can poll. When the timestamp becomes newer than your local last update time then refresh your view. Google has plenty of different variations on this theme.