Search code examples
c++databaseqtfeedlive

Live feed of values from a database Qt


I am writing an application on Qt that is constantly checking for data change on certain table using a QSqlQueryModel calling a query to retrieve the last value inserted on the database and comparing the timestamp in the row to the pervious value checked. I check every 100 ms using a timer calling a method which emits a signal telling that the data was changed or not. That however, creates a massive load on the processor sometimes rendering the computer useless until I close the app. I am only testing the performace of the platform for I need to implement it to many other tables in the same database and app in order to display the values on a sort of 'live' feed related to every table. I have read about Threads, but haven't really got a clue on how to implement it. Is there another way of doing this? What would you recomend me?


Solution

  • My guess is that your query takes more than 100ms to perform, so you are basically overloading the database with queries, stacking them on top of each other while the previous ones haven't finished.

    Do not use the restarting timer from QTimer, but a single-shot timer. Restart the timer only after your query has finished in your slot.