Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved]help for XmlListModel

[Solved]help for XmlListModel

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kathy
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cmer4
      wrote on last edited by
      #2

      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...
      1 Reply Last reply
      0
      • K Offline
        K Offline
        kathy
        wrote on last edited by
        #3

        Thank you. It solved my problem.

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

        1 Reply Last reply
        0
        • P Offline
          P Offline
          parancibia
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved