Hi,

On 14/07/2010, at 12:09 AM, ext Daker Fernandes wrote:

How to access a XmlListModel roles without any kind of View?

XmlListModel {
    id: xkcdModel
    source: "http://xkcd.com/100/";;

    XmlRole { name: "image"; query: "/title/text()" }
}

Text {
     text: xkcdModel.get(0).image
}

I really need to create a View? There is a better way to do it?

The ListModel classes are really designed to be used by the views (and other 
elements that know about models). So the above can be made to work, but it is 
not optimal:

XmlListModel {
    source: "http://xkcd.com/100/";;
    query: "/html/head"
    namespaceDeclarations: "declare default element namespace 
'http://www.w3.org/1999/xhtml';"

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

    onStatusChanged: {
        if (status == XmlListModel.Ready)
            titleText.text = get(0).image;
    }
}

Text {
    id: titleText
}

Note that get() won't work in a binding -- before the model is loaded it 
returns an undefined object, and currently the engine doesn't have a reliable 
way of knowing when that binding would need to be updated. This is quite 
non-intuitive (and something we've tried very hard to avoid), so I think we 
should look at whether we can improve the docs, error message, and/or behavior 
in this case.

We'll be looking more at models after the 4.7 release, including looking at 
making them more generically accessible. On the other hand, for this particular 
case a new XmlObject element would probably make more sense than using 
XmlListModel (given that there is no list involved).

Regards,
Michael
_______________________________________________
Qt-qml mailing list
Qt-qml@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-qml

Reply via email to