[Interest] Call on 'undefined' with default property
Wehmer, Matthias
Matthias.Wehmer at draeger.com
Mon Jun 29 16:32:26 CEST 2015
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150629/f7b750e0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5658 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150629/f7b750e0/attachment.bin>
More information about the Interest
mailing list