7

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

Bupa
  • 217
  • 1
  • 3
  • 7

4 Answers4

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
  • 1
    The 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
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:

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

Mitch
  • 23,716
  • 9
  • 83
  • 122
0

For example there is this loader:

Loader {
    id: loaderLanguage
}

to inactive:

loaderLanguage.active= false
iam_peter
  • 3,205
  • 1
  • 19
  • 31
M.M
  • 11
  • 2