[Solved]help for XmlListModel



  • I try to use XmlListModel for my GridView using Creator 2.2 on Windows XP. I am using Qt 4.7.3 library.

    My XML file - img.xml
    @<?xml version="1.0" encoding="utf-8"?>
    <root>
    <item>
    <title>scene_1</name>
    <source>common/pics/scene_1.jpg</source>
    </item>
    <item>
    <title>scene_2</title>
    <source>common/pics/scene_2.jpg</source>
    </item>
    <item>
    <title>scene_3</title>
    <source>common/pics/scene_3.jpg</source>
    </item>
    <item>
    <title>scene_4</title>
    <source>common/pics/scene_4.jpg</source>
    </item>
    <item>
    <title>scene_5</title>
    <source>common/pics/scene_5.jpg</source>
    </item>
    <item>
    <title>scene_6</title>
    <source>common/pics/scene_6.jpg</source>
    </item>
    <item>
    <title>scene_7</title>
    <source>common/pics/scene_7.jpg</source>
    </item>
    <item>
    <title>scene_8</title>
    <source>common/pics/scene_8.jpg</source>
    </item>
    </root>@

    the XmlListModel file - MyModel
    @XmlListModel {
    source: "./img.xml"
    query: "/root/item"

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

    }@

    and main.qml:
    @import QtQuick 1.0
    import "models" as Models

    Rectangle {
    width: 360
    height: 360

    Models.MyModel { id: xmlModel }
    ListView {
        width: 640; height: 480
        model: xmlModel
        delegate: Text { text: title }
    }
    

    }@

    When I run it, just blank page and no error show up. What is the problem?



  • Hi,

    1. Please check your XML file - you have first element (title) there closing as </name>
    2. try to put your xml file into the same folder first and use direct reference: source: "img.xml" in your XmlListView and try it out...


  • Thank you. It solved my problem.

    But I do not know how to set this as [sloved]



  • @kathy only add "Solved" to the title of this post


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.