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. How to clean ListModel data from a ListView, when model changes?[SOLVED/not an issue]
Forum Updated to NodeBB v4.3 + New Features

How to clean ListModel data from a ListView, when model changes?[SOLVED/not an issue]

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 3.1k 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
    cmer4
    wrote on last edited by
    #1

    Hi all, I was experimenting further with ListViews and recently found the following:

    • if a ListView has rendered ListModel, changing ListView.model to a new model doesn't "clear" the data from the previous model. Meaning in my example below though new model contains only "Cow" you still see the "Cat".

    Is there a way to clear the view?

    @import QtQuick 1.0

    Item {
    width: 200; height: 250

     ListModel {
         id: myModel
         ListElement { type: "Dog"; age: 8 }
         ListElement { type: "Cat"; age: 5 }
     }
     ListModel {
         id: myModel2
         ListElement { type: "Cow"; age: "3" }
     }
    
    
     Component {
         id: myDelegate
         Rectangle {
             id: rect3
             width: 300
             height: 300
             Text { text: type + ", " + age }
             Text {
                 text: "BUTTON"
                 y: 50
                 MouseArea {
                     anchors.fill: parent
                     onClicked: myview.model = myModel2
                 }
             }
         }
     }
    
     ListView {
         id: myview
         anchors.fill: parent
         model: myModel
         delegate: myDelegate
     }
    

    }@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      apap_
      wrote on last edited by
      #2

      I tried your example, it works well for me. When I push the button it changes the model and refresh the view.
      I work with Qt 4.7.1 Linux.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thisisbhaskar
        wrote on last edited by
        #3

        It works well. Windows XP machine with Nokia Qt SDK 1.1.

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

          Hmm wierd, seems like my laptop is slow or I messed the big code a bit...I will dig a bit further before maring this as SOLVED/not an issue...

          UPD: thanks for your replies! - indeed its my slow PC that caused some graphics glitches...the code works

          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