QML TableView automatically update when SQLite data changes
I was successfully able to populate a TableView in QML with data from my SQLite database using QAbstractTableModel as an inherited class and filling the rows using QList on my C++ backend. On the QML frontend I fill TableViewColumn and fill the columns with the roles from my c++ model. One thing that I have no idea how to do is update the QML TableView when there has been a change in the SQLite data. I can add data to the database but I dont have a clue how to refresh the QML table. Any ideas?
You need to update the model. This will automatically update the view. Are you using SQL Model classes. Things may become further easier for you.
I do update the model and it doesnt update the table. I am not using SQL model classes.
[quote author="Dheerendra" date="1392257732"]You need to update the model. This will automatically update the view. Are you using SQL Model classes. Things may become further easier for you.[/quote]
What have you reimplemented yourself from the QAbstractTableModel?
I have achieved a similar thing using a QSqlQueryModel. This inherits a QAbstractTableModel.
From documentation is states that the models based on QAbstractTableModels should automatically inform views when the data within them changes. However if in your custom implementation you have not emitted the dataChanged() signal where it would usually be signaled the view will not be updated.
Hopefully this helps. If you are still stuck on this and would like more information on how I have achieved this with the QSqlQueryModel please let me know.
Can you show us the code here? I also have the same question.