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. Updating the Values in AbstractListModel in Qt
QtWS25 Last Chance

Updating the Values in AbstractListModel in Qt

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 1.1k 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.
  • S Offline
    S Offline
    Sanjeev Gudisagar
    wrote on last edited by aha_1980
    #1

    I am facing a problem in updating a QAbstractListmodel, i have used qml for front end and qt for back end, i have used QList as a data structure for model , i am clearing contents of QList at start and added new values to the QList, i am getting the count of the list as 0, but the view is taking both old values plus new value, Is there a way so that modified values instantly reflected in the view and old values should not be shown not shown?

    JonBJ 1 Reply Last reply
    0
    • S Sanjeev Gudisagar

      I am facing a problem in updating a QAbstractListmodel, i have used qml for front end and qt for back end, i have used QList as a data structure for model , i am clearing contents of QList at start and added new values to the QList, i am getting the count of the list as 0, but the view is taking both old values plus new value, Is there a way so that modified values instantly reflected in the view and old values should not be shown not shown?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Sanjeev-Gudisagar
      That should already be the case. I suspect you're not going to get any help without supplying your code.

      1 Reply Last reply
      1
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        Did you write a custom model ? Are you using Qlist inside the QAbstractListmodel ? Are you inserting the content inside the list ? Are you sending the dataChanged(..) signal ? Are you calling beginInsert() and endInsert() functions before inserting ?

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        1
        • S Offline
          S Offline
          Sanjeev Gudisagar
          wrote on last edited by Sanjeev Gudisagar
          #4

          @dheerendra Yes i have used custom model, Yes i have used QList inside QAbstractListModel, Yes i am inserting content inside a list, i am not sending the dataChanged() signal, yes i have called both Insert functions before inserting.

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            Are you cleaning the contents of entire model & inserting the fresh rows or just updating few rows inside the model ?

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            S 2 Replies Last reply
            1
            • dheerendraD dheerendra

              Are you cleaning the contents of entire model & inserting the fresh rows or just updating few rows inside the model ?

              S Offline
              S Offline
              Sanjeev Gudisagar
              wrote on last edited by
              #6

              @dheerendra i am updating the model with new rows

              1 Reply Last reply
              0
              • dheerendraD dheerendra

                Are you cleaning the contents of entire model & inserting the fresh rows or just updating few rows inside the model ?

                S Offline
                S Offline
                Sanjeev Gudisagar
                wrote on last edited by
                #7

                @dheerendra i have cleared the contents of QList, since model contains QList clearing the contents of QList should automaically update the model OR Should i have to explicitly tell model to update?

                VRoninV 1 Reply Last reply
                0
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by
                  #8

                  Did you try to reset the model ? like begineResetModel and endResetModel ?

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  S 1 Reply Last reply
                  1
                  • S Sanjeev Gudisagar

                    @dheerendra i have cleared the contents of QList, since model contains QList clearing the contents of QList should automaically update the model OR Should i have to explicitly tell model to update?

                    VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #9

                    @Sanjeev-Gudisagar said in Updating the Values in AbstractListModel in Qt:

                    should automaically update the model

                    How? the model has no way of knowing what happens to your QList. you need to beginRemoveRows/endRemoveRows to tell the model you are removing items from the model.

                    Subclassing models is a messy business, you can use QAbstractItemModelTester to help you spot common mistakes

                    "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

                    1 Reply Last reply
                    2
                    • dheerendraD dheerendra

                      Did you try to reset the model ? like begineResetModel and endResetModel ?

                      S Offline
                      S Offline
                      Sanjeev Gudisagar
                      wrote on last edited by Sanjeev Gudisagar
                      #10

                      @dheerendra i have used both of them its working fine, thank you

                      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