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. How to set an .xml file as datasource to Listview

How to set an .xml file as datasource to Listview

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 668 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.
  • M Offline
    M Offline
    Mathan M
    wrote on last edited by Mathan M
    #1

    Hi,

    I am writing an rexlog.xml will be the data source to Listview in main.qml. But, The listview is not showing the value. In the xml the values are written and it is accessable.

    Query: I suspect, there will be performance issue, reading from .xml file and loading to Listview, Instead of that Is it good to load the data initially to QList or any similiar, so the listview can easily fetch the data for many events like scroll up/down.

    Which option will be better? The xml entry can be atleast 80-100 set of data.

    Code snippets:
    main.qml

    property string strXMLPath: System.userHomePath + "/rexlog.xml" //.xml file stored in the c:\user\proile\rexlog.xml
    
    
    XmlListModel {
    id: idXMLListModel
    source: strXMLPath 
    query: "/catalog/book"
    XmlRole {name: "title"; query: "title/string()"}
    
    XmlRole { name: "first_author"; query: "author[1]/string()" }
    XmlRole { name: "year"; query: "year/number()" }
    }
    
    
    //Note: Add the click event for ListView
    ListView {
    anchors {
    left: parent.left
    leftMargin: 10 * scaleFactor
    right: parent.right
    rightMargin: 10 * scaleFactor
    top: rectangleToolBar.bottom
    topMargin: 10 * scaleFactor
    bottom: rectangleStatusBar.top
    bottomMargin: 10 * scaleFactor
    }
    
    model: idXMLListModel
    delegate: Column {
    Layout.alignment: Qt.AlignCenter
    Text { text: title + " (" + type + ")"; font.bold: wanted }
    Text { text: first_author }
    Text { text: year }
    }
    }
    
    Component {
    id: comsearchDelegate
    
    Row {
    spacing: 10 * scaleFactor
    
    Image {
    id: imageItem
    width: 100 * scaleFactor
    height: 70 * scaleFactor
    source: thumbnailUrl
    }
    
    Column {
    Layout.alignment: Qt.AlignTop
    Text { text: Title; font { pixelSize: 14 * scaleFactor; bold: true } }
    
    }
    }
    }
    

    .xml

    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    -<catalog>
    
    
    -<book wanted="true" type="Online">
    
    <title>Qt 5 Cadaques</title>
    
    <year>2014</year>
    
    <author>Juergen Bocklage-Ryannel</author>
    
    <author>Johan Thelin</author>
    
    </book>
    
    
    -<book type="Hardcover">
    
    <title>C++ GUI Programming with Qt 4</title>
    
    <year>2006</year>
    
    <author>Jasmin Blanchette</author>
    
    <author>Mark Summerfield</author>
    
    </book>
    
    
    -<book type="Paperback">
    
    <title>Programming with Qt</title>
    
    <year>2002</year>
    
    <author>Matthias Kalle Dalheimer</author>
    
    </book>
    
    </catalog>
    

    Thanks In advance

    Edit: Added code formating tags -- @Wieland

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! ListView already implements caching to increase performance, no need to duplicate that.

      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