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 inform listview that model data has changed?
Forum Updated to NodeBB v4.3 + New Features

How to inform listview that model data has changed?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 2.9k 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.
  • P Offline
    P Offline
    philk
    wrote on last edited by
    #1

    Whats the recommended way to notify the listview that an item in its model has changed?
    I would like to not use the layoutChanged() signal, as it seems to be to verbose. I already know which item has changed, and want to signal only this particular item.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can use "dataChanged":http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#dataChanged with both first and last item pointing to the same index.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        philk
        wrote on last edited by
        #3

        Thanks, and how would my model item know about the model its contained in to inform it?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I am not sure I am following you correctly:

          You do have a custom model right ?
          The where does your changes come from ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Offline
            P Offline
            philk
            wrote on last edited by
            #5

            Lets say the changes come from a file system change listener. The display text of the model item should change, when its underlying file changes.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              If your model is custom, the listener should notify your model that something has changed, then you should update the model content and emit the signal

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • P Offline
                P Offline
                philk
                wrote on last edited by
                #7

                Let me explain using some pseudo code:
                @
                class ModelItem {
                ModelItem(file) {
                registerChangeHandler(file, this, &ModelItem::fileChanged)
                }

                void fileChanged(file) {
                // How do I update the model, this ModelItem is part of?
                }
                }

                class Model : public QAbstractItemModel {
                }
                @
                In fileChanged() how do I update my model, which will then in turn update the UI?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Are you sure that fileChanged should be in the item and not the model ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    philk
                    wrote on last edited by
                    #9

                    Yes, because other items of the Model are not backed by a File, and don't need change listeners. Every item knows better how it should update itself. The Model is just a collection of different items.

                    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