[Interest] Interest Digest, Vol 45, Issue 88

Wehmer, Matthias Matthias.Wehmer at draeger.com
Mon Jun 29 16:51:43 CEST 2015


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: interest-bounces+matthias.wehmer=draeger.com at qt-project.org
[mailto:interest-bounces+matthias.wehmer=draeger.com at qt-project.org] On
Behalf Of interest-request at qt-project.org
Sent: Monday, June 29, 2015 4:33 PM
To: interest at qt-project.org
Subject: Interest Digest, Vol 45, Issue 88

Send Interest mailing list submissions to
	interest at qt-project.org

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
	interest-request at qt-project.org

You can reach the person managing the list at
	interest-owner at qt-project.org

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" <Matthias.Wehmer at draeger.com>
Subject: [Interest] Call on 'undefined' with default property
To: "interest at qt-project.org" <interest at qt-project.org>
Message-ID:
	
<FF94C82C79CB224A87098FBB2BC103FA38F49B48 at 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
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


End of Interest Digest, Vol 45, Issue 88
****************************************
-------------- 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/798740fc/attachment.bin>


More information about the Interest mailing list