how to refresh data in QTableView from an SQLITE db while allowing the user to scroll and view the data
-
Hi everyone,
I hava an sqlite db and use a QTableView to present the underlying data to the user.
I insert data arriving from the network into the sqlite db at 50/100 msec intervals.A timer is used that is triggered every second and in its slot i call "select()" on the model.
This causes the data to be repopulated every second for the model/view BUT ... the user can not effectively scroll the tableView and inspect the data.
(it seems On each refresh, the view initially shows the first 256 rows)How can I allow the user to scroll the data while continously appending new data to the tableView (the scroll-bar should reflect arriving new data )
-
Since you put the new data into the database you know which data you have to add to your tableview - either add them directly or select only the new rows (e.g. by the pk).
-
Since you put the new data into the database you know which data you have to add to your tableview - either add them directly or select only the new rows (e.g. by the pk).
@Christian
could you please elaborate;- What do you mean by adding them directly? or
- What do you mean by selecting the new rows (pk=primary key??)
My code is simple & straight forward:
//open db connection auto db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("log.db"); //set model-view relationship between TableView and DB model = new QSqlTableModel(this); model->setTable("Logs"); model->select(); ui->tableView->setModel(model); .... //refresh data in the view connect(m_timer, &QTimer::timeout, [&](){model->select();} ); m_timer->start(1000);
Could you pls be more specific and help me out?
-
@alex_qwa said in how to refresh data in QTableView from an SQLITE db while allowing the user to scroll and view the data:
I insert data arriving from the network into the sqlite db at 50/100 msec intervals.
Here you know which data is put into the db, so you also know which new data needs to be added to the view.
-
@alex_qwa said in how to refresh data in QTableView from an SQLITE db while allowing the user to scroll and view the data:
I insert data arriving from the network into the sqlite db at 50/100 msec intervals.
Here you know which data is put into the db, so you also know which new data needs to be added to the view.
-
I would never use QSqlTableModel since it's to static - I don't know why someone simply would display the plain content of a table. But that's my personal opinion.
Yes - I would not use QSqlTableModel here, esp. wrt the update rate.