qml 4.8 bug: ListView.view不能访问

提示:TypeError: Result of expression 'ListView.view' [null] is not an object.

import QtQuick 1.0

Rectangle {
     width: 200; height: 200

    ListModel {
    id: fruitModel
    property string language: "en"
    ListElement {
        name: "Apple"
        cost: 2.45
    }
    ListElement {
        name: "Orange"
        cost: 3.25
    }
    ListElement {
        name: "Banana"
        cost: 1.95
    }
    }

    Component {
    id: fruitDelegate
    Row {
        Text { text: " Fruit: " + name; color: ListView.view.fruit_color }
        Text { text: " Cost: $" + cost }
        Text { text: " Language: " + ListView.view.model.language }
    }
    }

    ListView {
    property color fruit_color: "green"
    model: fruitModel
    delegate: fruitDelegate
    anchors.fill: parent
    }
}

 

'ListView.view' 是一个attached property

This attached property holds the view that manages this delegate instance.

It is attached to each instance of the delegate.

posted @ 2011-10-20 18:25  katago  阅读(467)  评论(0)    收藏  举报