Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to refresh data in QTableView from an SQLITE db while allowing the user to scroll and view the data

how to refresh data in QTableView from an SQLITE db while allowing the user to scroll and view the data

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 876 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.
  • A Offline
    A Offline
    alex_qwa
    wrote on last edited by
    #1

    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 )

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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).

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        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).

        A Offline
        A Offline
        alex_qwa
        wrote on last edited by
        #3

        @Christian
        could you please elaborate;

        1. What do you mean by adding them directly? or
        2. 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?

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          A 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @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.

            A Offline
            A Offline
            alex_qwa
            wrote on last edited by
            #5

            @Christian. (Thanks for taking time to answer me.)
            You are right, I know the new records that have been added to my table BUT do you mean that I should not use the QSqlTableModel and add the data to my view based on a custom user defined model ???!!!

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              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