2
votes

In qml i have a page main.qml, if i click on rectangle in that page it opens a component from second.qml file and a listview appears. The listview is very long and can be scrolled down. To go out to the main.qml (previous page) from second.qml it is also done by creating a back button. So far everything is ok and it works and is done by using loader and then changing the loader source.

The problem starts when i revisit the second.qml after clicking again on the rectangle in main.qml. This time it shows the listview left at the last time. What i want is to reload the second.qml as it loaded it first time. I have came across clear componentcache etc. However, it is not working for me.

A simple example on how to clear the cache memory of loader to reload it like i was loaded first time in qml would be helpful.

in main.qml

    MouseArea {
        anchors.fill: parent
        onClicked: {
            pp.close()

            //clearComponentCache(loader)

            loader.setSource("second.qml",
                             {   "x":0,
                                 "y":30});
            //loader.reload()


        }
    }
1
how do you unload second.html? what does the back button do?Soheil Armin
how to unload second.qml i simply load different qml pages via loader.sourceMandeep
That what i do with back button i simply change source of loader.Mandeep
This is not normal. Add Component.onDestruction:{console.log("second destroyed")} to your component to see if it is destructed.Soheil Armin

1 Answers

2
votes

I ran into a similar problem and I found a workaround which worked fine. (https://forum.qt.io/topic/102523/reload-a-loader-on-button-click/5)

  1. Deactivate loader
  2. Set the source
  3. Activate loader
loader.active = false;
loader.source = "some_file.qml";
loader.active = true;

As said, this is just a workaround and I would really like to know if there is clean way to do this.