[Development] Improving QtQuick internals (was Re: QML engine changes)
Nils Jeisecke
njeisecke at saltation.de
Thu Jun 27 09:47:18 CEST 2013
HI Alan,
see the following example for a real use case. I wouldn't say this is bad QML.
Destroying the loader's component will also destroy the component's
myTools row, although it has been reparented to another item. For this
use case it's just the right behavior but to be honest I've not yet
fully understood why. There must be a visual parent and an independent
ownership child list.
mail.qml
---
import QtQuick 2.0
Item {
width: 400
height: 400
Row {
id: toolContainer
}
Loader {
id: loader
anchors.top: toolContainer.bottom
source: "DynamicallyLoadedComponent.qml"
}
MouseArea {
anchors.fill: parent
onClicked: loader.source = "" // click to destroy component instance
}
}
DynamicallyLoadedComponent.qml
----
import QtQuick 2.0
Text {
text: "Bla Bla"
Row {
id: myTools
parent: toolContainer // <<<<< reparented!
Component.onDestruction: console.log("destroyed")
Repeater {
model: 5
Text {
text: "Tool " + modelData
}
}
}
}
Nils
More information about the Development
mailing list