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. ListView and changes in model
Forum Updated to NodeBB v4.3 + New Features

ListView and changes in model

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 5 Posters 8.5k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    cjavax
    wrote on last edited by
    #1

    I using QDeclarativeView to display content of QList<my_class> in ListView. That working fine. But if data in QList<my_class> was been modified, QDeclarativeView don't display that changes. How to notify ListView about changes in model ?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      It is not possible to notify ListView about changes in QList (but you can reassign property with QList and it will help you). If you want notify declarative ListView about C++ model changes you should create class with QAbstractListModel inherited and notify via standard model mechanisms.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aalpert
        wrote on last edited by
        #3

        If you exposed the QList via setContextProperty, you will need to set the list again every time the data in it changes.

        If you exposed the list via a Q_PROPERTY, you should emit the notify signal for that property every time the list data changes.

        Either way, it won't happen by magic. You need to somehow communicate that the list has changed. If you want it to happen 'by magic', then use the QAbstractListModel approach (where you still have to indicate that it has changed, but once you indicate it to the model it will automatically propagate to QML).

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

          Thanks for explanations

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jzellner
            wrote on last edited by
            #5

            There is a rather complete example for a folderlist in the docs:

            http://doc.qt.nokia.com/4.7-snapshot/src-imports-folderlistmodel.html

            1 Reply Last reply
            0
            • A Offline
              A Offline
              archerabi
              wrote on last edited by
              #6

              whenever that data in the model changes make sure to call dataChanged() in the model.This will update the listView.

              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