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
QML Loader ... How to unload or delete a qml page loaded on to Loader element
Asked Answered
Can you show us some code, where you tried it (mcve)? –
Duran
You should set sourceComponent = undefined
or source = ""
.
Usually, I use this code:
Loader{
id: loader
function show(component) {
sourceComponent = component;
}
function hide(){
sourceComponent = undefined;
}
}
The documentation clearly say that you need to specify undefined instead of null, still, this solved the issue for me :) –
Americano
You can just set the active
property to false
for unload or true
(default) for loading.
Such a simple and concise solution. This has become my preferred way. –
Nimbus
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:
For example there is this loader:
Loader {
id: loaderLanguage
}
to inactive:
loaderLanguage.active= false
© 2022 - 2024 — McMap. All rights reserved.