Results 1 to 5 of 5

Thread: How to set an .xml file as datasource to Listview

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2016
    Posts
    53
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default How to set an .xml file as datasource to Listview

    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
    -----------
    Qt Code:
    1. property string strXMLPath: System.userHomePath + "/rexlog.xml" //.xml file stored in the c:\user\proile\rexlog.xml
    2.  
    3.  
    4. XmlListModel {
    5. id: idXMLListModel
    6. source: strXMLPath
    7. query: "/catalog/book"
    8. XmlRole {name: "title"; query: "title/string()"}
    9.  
    10. XmlRole { name: "first_author"; query: "author[1]/string()" }
    11. XmlRole { name: "year"; query: "year/number()" }
    12. }
    13.  
    14.  
    15. //Note: Add the click event for ListView
    16. ListView {
    17. anchors {
    18. left: parent.left
    19. leftMargin: 10 * scaleFactor
    20. right: parent.right
    21. rightMargin: 10 * scaleFactor
    22. top: rectangleToolBar.bottom
    23. topMargin: 10 * scaleFactor
    24. bottom: rectangleStatusBar.top
    25. bottomMargin: 10 * scaleFactor
    26. }
    27.  
    28. model: idXMLListModel
    29. delegate: Column {
    30. Layout.alignment: Qt.AlignCenter
    31. Text { text: title + " (" + type + ")"; font.bold: wanted }
    32. Text { text: first_author }
    33. Text { text: year }
    34. }
    35. }
    36.  
    37. Component {
    38. id: comsearchDelegate
    39.  
    40. Row {
    41. spacing: 10 * scaleFactor
    42.  
    43. Image {
    44. id: imageItem
    45. width: 100 * scaleFactor
    46. height: 70 * scaleFactor
    47. source: thumbnailUrl
    48. }
    49.  
    50. Column {
    51. Layout.alignment: Qt.AlignTop
    52. Text { text: Title; font { pixelSize: 14 * scaleFactor; bold: true } }
    53.  
    54. }
    55. }
    56. }
    To copy to clipboard, switch view to plain text mode 

    .xml
    -----
    Qt Code:
    1. <?xml version="1.0" encoding="ISO-8859-1"?>
    2.  
    3. -<catalog>
    4.  
    5.  
    6. -<book wanted="true" type="Online">
    7.  
    8. <title>Qt 5 Cadaques</title>
    9.  
    10. <year>2014</year>
    11.  
    12. <author>Juergen Bocklage-Ryannel</author>
    13.  
    14. <author>Johan Thelin</author>
    15.  
    16. </book>
    17.  
    18.  
    19. -<book type="Hardcover">
    20.  
    21. <title>C++ GUI Programming with Qt 4</title>
    22.  
    23. <year>2006</year>
    24.  
    25. <author>Jasmin Blanchette</author>
    26.  
    27. <author>Mark Summerfield</author>
    28.  
    29. </book>
    30.  
    31.  
    32. -<book type="Paperback">
    33.  
    34. <title>Programming with Qt</title>
    35.  
    36. <year>2002</year>
    37.  
    38. <author>Matthias Kalle Dalheimer</author>
    39.  
    40. </book>
    41.  
    42. </catalog>
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 1st October 2016 at 15:08. Reason: missing [code] tags

Similar Threads

  1. Replies: 2
    Last Post: 16th May 2016, 23:50
  2. ListView - ListView communication
    By MarkoSan in forum Qt Quick
    Replies: 1
    Last Post: 30th October 2015, 10:18
  3. TWAIN Datasource in Qt
    By astodolski in forum Qt Programming
    Replies: 4
    Last Post: 19th November 2013, 21:31
  4. qml listview
    By Le_B in forum Qt Quick
    Replies: 1
    Last Post: 25th May 2011, 13:01
  5. listview
    By addu in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2009, 12:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.