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

bea.lam at nokia.com bea.lam at nokia.com
Tue Nov 22 09:41:31 CET 2011


On 22/11/2011, at 6:15 PM, ext Harri Pasanen wrote:
> [snip]
> 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.
> 


Ah, I see - in this case, the PieChart class needs to pass an AtFunction as well as a AppendFunction to the QDeclarativeListProperty constructor. The AtFunction will provide index-based access to objects within the list. In the BirthdayParty example, this functionality was added automatically, since the example used the convenience constructor of QDeclarativeListProperty.

cheers,

Bea


More information about the Qt-qml mailing list