Hi everybody,
I guess I found my error: When reparenting, the item is already deleted from
the child list! Wasn't aware of that. So
When changing the corresponding lines for what to do when changing the
content to this:
...
onContentChanged: {
if(flickable.children[1] === undefined )
return
flickable.children[1].parent = flickable.contentItem
if( flickable.contentItem.children[0] === undefined )
return
flickable.contentHeight = flickable.contentItem.children[0].height
flickable.contentWidth = flickable.contentItem.children[0].width
}
...
Everything works out fine.
Anyway, thanks for thinking about my problem.
Best regards,
Matthias
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On
Behalf Of [email protected]
Sent: Monday, June 29, 2015 4:33 PM
To: [email protected]
Subject: Interest Digest, Vol 45, Issue 88
Send Interest mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://lists.qt-project.org/mailman/listinfo/interest
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific than
"Re: Contents of Interest digest..."
Today's Topics:
1. Call on 'undefined' with default property (Wehmer, Matthias)
----------------------------------------------------------------------
Message: 1
Date: Mon, 29 Jun 2015 14:32:26 +0000
From: "Wehmer, Matthias" <[email protected]>
Subject: [Interest] Call on 'undefined' with default property
To: "[email protected]" <[email protected]>
Message-ID:
<ff94c82c79cb224a87098fbb2bc103fa38f49...@ddcrfra120.corp.draeger.global>
Content-Type: text/plain; charset="us-ascii"
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
------------------------------
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest
End of Interest Digest, Vol 45, Issue 88
****************************************
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Interest mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/interest
