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. Dynamically updating QML ListView

Dynamically updating QML ListView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 5 Posters 4.3k 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.
  • R Offline
    R Offline
    RyonMS
    wrote on last edited by
    #1
    This post is deleted!
    E 1 Reply Last reply
    0
    • R RyonMS

      This post is deleted!

      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @RyonMS Can you use QStringListModel?

      R 1 Reply Last reply
      0
      • E Eeli K

        @RyonMS Can you use QStringListModel?

        R Offline
        R Offline
        RyonMS
        wrote on last edited by
        #3

        @Eeli-K I could, I was actually just looking at doing this. I'm new to the Qt framework and don't really know much about it.

        mrjjM 1 Reply Last reply
        0
        • R RyonMS

          @Eeli-K I could, I was actually just looking at doing this. I'm new to the Qt framework and don't really know much about it.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @RyonMS
          Hi and welcome
          I assume you did stumble upon
          http://doc.qt.io/qt-5/model-view-programming.html

          R 1 Reply Last reply
          1
          • mrjjM mrjj

            @RyonMS
            Hi and welcome
            I assume you did stumble upon
            http://doc.qt.io/qt-5/model-view-programming.html

            R Offline
            R Offline
            RyonMS
            wrote on last edited by
            #5

            @mrjj Hello and thanks for the welcome! I have read through that page, but I'm still a bit lost. I have a class that now contains a QStringListModel for the ListView in QML. I just still don't know how to hook this model up to the QML.

            RajeeshRaveendranR E 2 Replies Last reply
            0
            • R RyonMS

              @mrjj Hello and thanks for the welcome! I have read through that page, but I'm still a bit lost. I have a class that now contains a QStringListModel for the ListView in QML. I just still don't know how to hook this model up to the QML.

              RajeeshRaveendranR Offline
              RajeeshRaveendranR Offline
              RajeeshRaveendran
              wrote on last edited by
              #6

              @RyonMS : You can create a property of QStringList from your cpp class. And then create a instance of the class register it with QML.

              Please refer below thread in which I created a sample code.

              https://forum.qt.io/topic/76845/how-to-get-a-listmodel-to-update-from-a-signal/2

              If you still doubt ask me.! welcome.

              Regards,
              Rajeesh Raveendran

              R 1 Reply Last reply
              1
              • R RyonMS

                @mrjj Hello and thanks for the welcome! I have read through that page, but I'm still a bit lost. I have a class that now contains a QStringListModel for the ListView in QML. I just still don't know how to hook this model up to the QML.

                E Offline
                E Offline
                Eeli K
                wrote on last edited by
                #7

                @RyonMS See also http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html. There you can see some options and examples. You can use QStringList as a model but it doesn't update automatically, but

                "Note: There is no way for the view to know that the contents of a QStringList have changed. If the QStringList changes, it will be necessary to reset the model by calling QQmlContext::setContextProperty() again."

                I didn't get it working even with setContextProperty(), however.

                QStringListModel is a QAbstractItemModel subclass.

                AlienA 1 Reply Last reply
                0
                • E Eeli K

                  @RyonMS See also http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html. There you can see some options and examples. You can use QStringList as a model but it doesn't update automatically, but

                  "Note: There is no way for the view to know that the contents of a QStringList have changed. If the QStringList changes, it will be necessary to reset the model by calling QQmlContext::setContextProperty() again."

                  I didn't get it working even with setContextProperty(), however.

                  QStringListModel is a QAbstractItemModel subclass.

                  AlienA Offline
                  AlienA Offline
                  Alien
                  wrote on last edited by Alien
                  #8

                  Dear @RyonMS ,

                  Have a look at "AbstractItemModel Example " in addAnimal function it uses

                  beginInsertRows(QModelIndex(), rowCount(), rowCount());
                  

                  and

                  endInsertRows();
                  

                  Also I implement my own subclass of QAbstractListModel and it works fine to me (dynamically update the values).
                  Of course you can change your model from QStringList to QList<Qstring> to become more similar to the example.

                  I hope this may help you

                  1 Reply Last reply
                  1
                  • RajeeshRaveendranR RajeeshRaveendran

                    @RyonMS : You can create a property of QStringList from your cpp class. And then create a instance of the class register it with QML.

                    Please refer below thread in which I created a sample code.

                    https://forum.qt.io/topic/76845/how-to-get-a-listmodel-to-update-from-a-signal/2

                    If you still doubt ask me.! welcome.

                    Regards,
                    Rajeesh Raveendran

                    R Offline
                    R Offline
                    RyonMS
                    wrote on last edited by
                    #9

                    @RajeeshRaveendran Using your example I think I have it working now! Really appreciate your help!

                    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