QSqlQueryModel making singleton and also update tableview
-
Hi,
I am using QSqlQueryModel to display table from database. But I have different tables to display, can't I use same instance instead of creating different instance for each table.Using like this now TableModel aTable, bTable; engine.rootContext()->setContextProperty("aTable", &aTable); engine.rootContext()->setContextProperty("bTable", &bTable); instead can I use this way engine.rootContext()->setContextProperty("tableModel", TableModel::getInstance()); --> but this load same table all over
and also when there is a update in database, I wanted to update tableView automatically rather than using timer in QML.
void TableModel::refresh() { clear(); beginResetModel(); this->query().clear(); setQuery(queryString); endResetModel(); }
but this doesn't update till I call this way in QML
Timer { id: timer interval: 10 running: true repeat: true onTriggered: { aTable.refresh() } }
but this approach is not feasible as this take lot of CPU time and also need not scan every 10ms as there might not be an update always.
Thanks in advance