[Qt-qml] [qt-qml] How to access a XmlListModel roles without any kind of View

Eduardo Fleury eduardo.fleury at openbossa.org
Wed Jul 14 20:11:45 CEST 2010


In one sense one could use XMLHttpRequest from Javascript to kind of parse
that kind of information from a XML file. In practice though, XMLHttpRequest
is such a can of worms and code using it looks so clumsy and ugly that
trying to use the Model can be the best approach for now...

On Tue, Jul 13, 2010 at 9:37 PM, <michael.brasser at nokia.com> wrote:

> 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' <http://www.w3.org/1999/xhtml%27>;"
>
>     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 at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-qml
>
>


-- 
Eduardo M. Fleury
OpenBossa - INdT
http://eduardofleury.com/
http://www.openbossa.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100714/902dab1c/attachment.html 


More information about the Qt-qml mailing list