[Qt-qml] Views and models
Cornelius Hald
hald at icandy.de
Tue Aug 10 10:48:22 CEST 2010
Hi Bea,
thanks a lot for your help. With the code you provided, I managed to
adapt my code to solve the problem. Having a ListView inside a ListView
when only really using one ListView is a bit counter intuitive at first,
but maybe I just need to adjust to the QML way :)
Anyways, I'm looking forward for improved model/view features in the
future.
Thanks again!
Conny
On Mon, 2010-08-09 at 08:59 +0200, bea.lam at nokia.com wrote:
> Hi Cornelius,
>
> On 07/08/2010, at 1:14 AM, ext Cornelius Hald wrote:
> > [...]
> >
> > So far, so good. I will get all sides from my first slide show. But how
> > can I, for example, access the <name> element of <slideshow>? And how
> > can I access the other slide shows?
> >
> > I would like to have a list, where each element looks like this:
> > * slide show name: /root/slideshow/name/string()
> > * slide text: /root/slideshow/slide/text/string()
> > * slide image: /root/slideshow/slide/image/string()
> > * More...
> >
> > I tried adding a XmlRole that accesses the parent element like:
> >
> > XmlRole { name: "parentName"; query: "../name/string()" }
> >
>
>
> It looks like you should start the query from "/root/slideshow" rather than "/root/slideshow/slide", and fetch the slideshow name using
>
> XmlRole { name: "name"; query: "name/string()" }
>
> To access each slide within a slideshow, you can create an inner XmlListModel that queries "/root/slideshow/slide" as you did before, but access a specific slide by its index, e.g. "root/slideshow/slide[1]" (see http://doc.qt.nokia.com/4.7-snapshot/qml-xmlrole.html). For example,
>
> ListView {
> width: 300; height: 400
> model: slideshow
> delegate: Column {
> Text { text: name }
>
> ListView {
> x: 50
> width: 300; height: childrenRect.height
> model: XmlListModel {
> source: "slideshow.xml"
> query: "/root/slideshow[" + (index + 1) + "]/slide"
>
> XmlRole { name: "image"; query: "image/string()" }
> XmlRole { name: "audio"; query: "audio/string()" }
> }
> delegate: Column {
> Text { text: "* Slide " + (index + 1) + ":" }
> Text { text: image }
> Text { text: audio }
> }
> }
> }
> }
>
> XmlListModel is focused on creating a model from xml data rather than fetching a single xml value. In a later release we'll look to improve support in this area as well.
>
>
> regards,
>
> Bea
More information about the Qt-qml
mailing list