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
Asked
Active
Viewed 7,619 times
7
-
Can you show us some code, [where you tried it (mcve)](http://stackoverflow.com/help/mcve)? – derM - not here for BOT dreams Feb 15 '17 at 15:57
4 Answers
7
You should set sourceComponent = undefined
or source = ""
.
Usually, I use this code:
Loader{
id: loader
function show(component) {
sourceComponent = component;
}
function hide(){
sourceComponent = undefined;
}
}

albertTaberner
- 1,969
- 1
- 26
- 35
-
1The documentation clearly say that you need to specify undefined instead of null, still, this solved the issue for me :) – Matteo Nov 07 '17 at 11:49
3
You can just set the active
property to false
for unload or true
(default) for loading.

Kevin Krammer
- 5,159
- 2
- 9
- 22
-
Such a simple and concise solution. This has become my preferred way. – Paul Masri-Stone Sep 29 '22 at 11:20
0
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:

Mitch
- 23,716
- 9
- 83
- 122