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. Avoid junk in GridView when dynamically changing XmlListModel's xml property
Forum Updated to NodeBB v4.3 + New Features

Avoid junk in GridView when dynamically changing XmlListModel's xml property

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 1.2k 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.
  • H Offline
    H Offline
    herophuong
    wrote on last edited by
    #1

    I use a GridView (with XmlListModel) to display the items belong to the category which is selected in a ListView. Each time an item is selected in the ListView, I dynamically change the xml property of the XmlListModel to the corresponding xml data for the category.

    The problem is, when dynamically changing the xml property, it left junk in the GridView, as you can see in the screencast (I've repeatedly changed between the second and third category): http://herophuong.co.cc/qml-gridview-error.ogv

    What should I do to avoid this? (May be clear the GridView after each change but how?)

    Here is some code for ones who need it:

    The GridView:

    @GridView {
    id: catView
    cellHeight: 160
    cellWidth: 160
    model: XmlListModel {
    id: dataModel
    query: "/methodResponse/params/param/value/array/data/value"
    XmlRole {name: "postId"; query:"struct/member[1]/value/string/number()"}
    XmlRole {name: "title"; query: "struct/member[2]/value/string/string()"}
    }
    delegate: Rectangle {
    id: wrapper2
    width: parent.width
    height: parent.height
    border.width: 1
    border.color: "white"
    color: "transparent"
    Column {
    spacing: 5
    Text {text: postId;}
    Text {text: title;}
    }
    }@

    The Timer (I use timer to wait for the xml data to be ready):

    @Timer {
    id: fetcher
    interval: 16
    running: true
    repeat: true
    onTriggered: {
    if (Script.ready === XMLHttpRequest.UNSENT) {
    Script.localtest() // start fetching data on localhost
    }
    if (Script.ready === XMLHttpRequest.DONE) {
    dataModel.xml = "" // try set this to blank to clear the model but it has no effect
    dataModel.xml = Script.data
    fetcher.stop()
    Script.ready = XMLHttpRequest.UNSENT // reset Script object
    }
    dataModel.reload() // also try reload() the model but it also has no effect
    }
    }@

    There's also a javascript function to set Script.category to other value before fetching data with Script.localtest()

    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