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 view when model data changes
QtWS25 Last Chance

How to refresh view when model data changes

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 8.9k 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
    advseo32
    wrote on last edited by
    #1

    Hello,

    i have a problem with Qtableview witch is considered like a view , and my model ( QsqlqueryModel )

    i have manipulate data in the model ( delete , add , ....etc ) , but the view not updating in real time

    i want a better way to informe the view with updating of model data

    1 Reply Last reply
    0
    • A Offline
      A Offline
      advseo32
      wrote on last edited by
      #2

      any one knows how we can do this ??

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tilsitt
        wrote on last edited by
        #3

        Hi,

        I'm not sure it will help, but maybe you can call update() on your QTreeView when your data change.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chris17
          wrote on last edited by
          #4

          QSqlQueryModel is read-only. Maybe you need QSqlTableModel instead.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            advseo32
            wrote on last edited by
            #5

            [quote author="chris17" date="1382593819"]QSqlQueryModel is read-only. Maybe you need QSqlTableModel instead.[/quote]

            i don't want to allow users , to be able to edit cells , i need it read it only,

            my problem is when other events make changes in database , and this changes affecte the my model , so, i need to update it immediatly

            1 Reply Last reply
            0
            • JeroentjehomeJ Offline
              JeroentjehomeJ Offline
              Jeroentjehome
              wrote on last edited by
              #6

              Hi,
              There are two ways of doing this. (when you read the documents you should have thought of this yourself).
              This first one is the update() function of the QAbstractItemView which QTableView inherits. The second is the reset function of the QAbstractItemView.
              The big difference is that the update gets an index of the positions in the table to refresh. The view does a complete rebuild, also loosing any selection behavior etc.
              Greetz

              Greetz, Jeroen

              1 Reply Last reply
              0
              • A Offline
                A Offline
                advseo32
                wrote on last edited by
                #7

                i have tried the two function but , they not work for me , the model still need to query the database again to be refresh

                her is my code

                @ connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),ui->tableView,SLOT(reset()));

                connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),ui->tableView,SLOT(update()));@

                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