5
votes

I have loaded MyItem.qml as a source component onto Loader element. Now i want to remove or unload that page from Loader element. I tried to set source : "" & sourceComponent : "" , also sourceComponent : "undefined". But it did not work

3
Can you show us some code, where you tried it (mcve)?derM

3 Answers

5
votes

You should set sourceComponent = undefined or source = "". Usually, I use this code:

Loader{
    id: loader
    function show(component) {
        sourceComponent = component;
    }
    function hide(){
        sourceComponent = undefined;
    }
}
2
votes

You can just set the active property to false for unload or true (default) for loading.

0
votes

You didn't say what the actual issue was, but in case you ran into errors where the component you're trying to unload is trying to access things it shouldn't, it could be because Loader deletes the item using deleteLater(), which means it doesn't get deleted instantly. See this bug report for more info:

https://bugreports.qt.io/browse/QTBUG-60344