[Qt-qml] Extending with C++, basic QML list type question

Harri Pasanen harri at mpaja.com
Tue Nov 22 09:15:15 CET 2011


On 11/22/2011 04:35 AM, bea.lam at nokia.com wrote:
> Hi Harri,
>
> On 22/11/2011, at 3:49 AM, ext Harri Pasanen wrote:
>> Chokes when it tries to index the guests property, spitting out a message:
>> 'guests[1]' [undefined] is not an object.
>>
>> Should this work, or what am I missing?
>
> I can't reproduce this error with the built-in example - but, based on the error, I'm guessing that in your code, the guests list hasn't actually been populated somehow, so guests[1] isn't actually referencing a valid object.
>

I reproduced my problem with the PieChart example.  The modified app.qml 
is as follows:

// --------------------------------------------
import Charts 1.0
import QtQuick 1.0

Item {
     width: 300; height: 200

     PieChart {
         id: pie
         anchors.centerIn: parent
         width: 100; height: 100

         slices: [
             PieSlice {
                 anchors.fill: parent
                 color: "red"
                 fromAngle: 0; angleSpan: 110
             },
             PieSlice {
                 anchors.fill: parent
                 color: "black"
                 fromAngle: 110; angleSpan: 50
             },
             PieSlice {
                 anchors.fill: parent
                 color: "blue"
                 fromAngle: 160; angleSpan: 100
             }
         ]
     }

     Component.onCompleted:  {
       console.log("completed")
       console.log(pie.slices)
       console.log(pie.slices[1].color)
     }
}


When I run chapter5-listproperties project with this, it spits out

TypeError: Result of expression 'pie.slices[1]' [undefined] is not an 
object.


I would have expected "black".

So what gives?

/Harri



More information about the Qt-qml mailing list