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. QML TableView automatically update when SQLite data changes
QtWS25 Last Chance

QML TableView automatically update when SQLite data changes

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 4.5k 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.
  • R Offline
    R Offline
    rizoritis
    wrote on last edited by
    #1

    Hello,

    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?

    Thank you!

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rizoritis
        wrote on last edited by
        #3

        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]

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrdeeds
          wrote on last edited by
          #4

          Hi,
          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.

          C 1 Reply Last reply
          0
          • M mrdeeds

            Hi,
            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.

            C Offline
            C Offline
            CoderJeff
            wrote on last edited by
            #5

            @mrdeeds

            Can you show us the code here? I also have the same question.

            Thank you.

            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