Hi everybody,
currently I am gathering further and further ( surprising J ) experiences
with the default property and the whole reparenting stuff in Qml.
To be concrete, here is the code for what I am currently doing:
import QtQuick 2.0
import QtQuick.Controls 1.2
Rectangle {
default property alias content: flickable.children
color: "red"
// Everytime we add another content as default property, we need to
reparent to keep the
// flickable functionality working.
onContentChanged: {
console.debug("blub")
console.debug(flickable.children[1])
if(flickable.children[1] === undefined )
return
console.debug("2",flickable.children[1])
flickable.children[1].parent = flickable.contentItem
flickable.contentHeight = flickable.children[1].height
flickable.contentWidth = flickable.children[1].width
}
Flickable {
id: flickable
anchors.fill: parent
interactive: true
boundsBehavior: Flickable.StopAtBounds
clip: true
}
}
What should it do? - Basically I just want to add arbitrary content (I call
it content object) as default property to my component and flick it around.
My problem are these two lines:
flickable.contentHeight = flickable.children[1].height
flickable.contentWidth = flickable.children[1].width
Everytime I call the code, I get the following message:
QT (Warning) qrc:///CommonUiBase/qml/CommonUiScrollPanel.qml:22: TypeError:
Cannot read property 'height' of undefined
Even though there is a check for an undefined item directly before the call
on it. And even more confusing is, that the second call to console is not
made, when the content object is undefined (correctly so).
When simply printing height or width of the content object to the console, I
got the correct values.
So why can't I access the height and width or why are they accessed even
though the content object is undefined?
Thanks a lot for your input.
Best regards,
Matthias
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Interest mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/interest
