Notification when database changes
-
Hi,
I wrote a QT desktop application which is used by different people. The application consits of several complex widgets which are aligned in a QTabBar. Every time the user clicks a tab, the model of the underlying widget fetches data from the database and populates the model. However, due to the complexity of the database queries, this takes some time.
I want to change this approach, so that the models are only populated once (typically at startup) and then these "local" models are used. If a user changes something, the "local" model get's changed and the changes are also written back to the database. However, as I mentioned before, the application is used by different people on different machines. So if User B changes something in the application on his machine, I want to reload the corresponding widget in User A's application.
How can I accomplish that in QT?
I know that it is possible to emit an asynchronous signal with PostgreSQL which can be captured with QT, but unfourtanely I have to use SQL Server.
The only solution I came up with is, to use a thread and periodically check if there are changes in the database. If that's the case, I re-populate the appropriate model. Is this the way to go here or exists there a more elegant solution to this?
Thanks for your help!
Kind Regards
Bernhard -
Hi, I'm having a bit of the same design problem, working with a healthcare app that also has to support legacy SQL Servers. In my case I want it to work also on Macs and Linux, so I'm stuck with Qt's vanilla QSqlDatabase and QSqlDriver. And when I query the driver for ::hasFeature(EventNotifications) it returns false :-( (but true for PostgreSQL).
So I guess I'm stuck with periodical polling.
But in your case, if you're on Windows only, I know for example .NET supports "SQLServer's Query Notifications":http://msdn.microsoft.com/en-us/library/ms130764.aspx So it should be possible to add this functionality with a Qt plugin or .dll.