开发者

Only one row of ListView populated in QML app, any idea why?

I'm trying to create a simple QML application that will get an RSS feed with my active chess games and do stuff with it. At this point I am just trying to populate a list view with the feed contents, but it only shows one item even when there should be 11 items in the feed. Is this a bug or am I not getting something right?

Here's the code:


    import Qt 4.7
    import "content"

    Rectangle {
        id : window;
        width : 320
        height : 480

        XmlListModel {
            id : xmlModel

            source : "http://gameknot.com/rss.pl?n=kEzvYvEgfHoOmzQzQlY/5w5ITO5YDN开发者_如何学C"
            query : "/rss/channel/item"

            XmlRole { name: "title"; query: "title/string()"}
            XmlRole { name: "description"; query: "description/string()"}
        }

        Column
        {
            id : mainContainer

                ListView
                {

                    id : list
                    model : xmlModel
                    delegate : ListDelegate { }
                    //delegate: Text { text: title }
                }
        }
    }

The delegate should be all right, because the same thing also happens with the simple delegate I have commented out.


Your model and view are fine, it's your layout that's wrong. Try adding anchors.fill: parent to mainContainer. That should fix it:

Column
{
    anchors.fill: parent
    id : mainContainer

    ListView
    {
        width: parent.width
        height: parent.height

        id : list
        model : xmlModel
        delegate : ListDelegate { }
        //delegate: Text { text: title }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜