Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QSqlQueryModel making singleton and also update tableview
Forum Updated to NodeBB v4.3 + New Features

QSqlQueryModel making singleton and also update tableview

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 130 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DhanyaRaghav
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved