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. ListView won't get updated when I change data in my custom model

ListView won't get updated when I change data in my custom model

Scheduled Pinned Locked Moved Unsolved General and Desktop
modelslistviewlistmodeldata models
11 Posts 3 Posters 1.8k 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.
  • C Offline
    C Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on 4 Feb 2019, 05:53 last edited by
    #2

    Are you sure you're calling dataChanged() with the correct values?

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

    I 1 Reply Last reply 4 Feb 2019, 15:20
    2
    • V Offline
      V Offline
      VRonin
      wrote on 4 Feb 2019, 09:17 last edited by
      #3

      can you show us your code?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      I 1 Reply Last reply 4 Feb 2019, 15:20
      0
      • C Christian Ehrlicher
        4 Feb 2019, 05:53

        Are you sure you're calling dataChanged() with the correct values?

        I Offline
        I Offline
        ivarec
        wrote on 4 Feb 2019, 15:20 last edited by
        #4

        @Christian-Ehrlicher I pass two QModelIndex objects, one initiated to the top left row and column of my change and one initiated to its bottom right. Via debugger, I can see that the values make sense. For example:

        My model has 4 columns (fixed, doesn't change). If I append a new row and my model previously had 2 rows, What I see is:

        topLeft -> 2, 0
        bottomRight -> 2, 3
        
        1 Reply Last reply
        0
        • V VRonin
          4 Feb 2019, 09:17

          can you show us your code?

          I Offline
          I Offline
          ivarec
          wrote on 4 Feb 2019, 15:20 last edited by
          #5

          @VRonin I will setup a minimal test case

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 4 Feb 2019, 16:29 last edited by
            #6

            And is the parent correct?

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

            I 1 Reply Last reply 4 Feb 2019, 16:31
            0
            • C Christian Ehrlicher
              4 Feb 2019, 16:29

              And is the parent correct?

              I Offline
              I Offline
              ivarec
              wrote on 4 Feb 2019, 16:31 last edited by
              #7

              @Christian-Ehrlicher my model is created once upon startup in main.cpp. I create it with my QGuiApplication as the parent. My ListView is also a child of this QGuiApplication. Is this the wrong way to do it?

              V 1 Reply Last reply 4 Feb 2019, 17:39
              0
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 4 Feb 2019, 16:43 last edited by
                #8

                The QModelndex you're passing to dataChanged() need a proper parent index: http://doc.qt.io/qt-5/model-view-programming.html#parents-of-items

                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
                • I ivarec
                  4 Feb 2019, 16:31

                  @Christian-Ehrlicher my model is created once upon startup in main.cpp. I create it with my QGuiApplication as the parent. My ListView is also a child of this QGuiApplication. Is this the wrong way to do it?

                  V Offline
                  V Offline
                  VRonin
                  wrote on 4 Feb 2019, 17:39 last edited by
                  #9

                  @ivarec said in ListView won't get updated when I change data in my custom model:

                  My ListView is also a child of this QGuiApplication.

                  This is unrelated but probably bad

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  I 1 Reply Last reply 4 Feb 2019, 18:13
                  0
                  • V VRonin
                    4 Feb 2019, 17:39

                    @ivarec said in ListView won't get updated when I change data in my custom model:

                    My ListView is also a child of this QGuiApplication.

                    This is unrelated but probably bad

                    I Offline
                    I Offline
                    ivarec
                    wrote on 4 Feb 2019, 18:13 last edited by
                    #10

                    @VRonin Maybe I've expressed myself badly, since I'm still a newbie in Qt. The ListView is created via QML. It's as basic as:

                    ListView {
                      id: list
                      model: myModel
                    }
                    

                    Maybe, when done like that, the parent of the ListView is not the application itself, which must be why you were surprised.

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 4 Feb 2019, 19:30 last edited by
                      #11

                      Can we finally see where and how you emit dataChanged()? And with which indexes?

                      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
                      1

                      11/11

                      4 Feb 2019, 19:30

                      • Login

                      • Login or register to search.
                      11 out of 11
                      • First post
                        11/11
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved