Mathan
1st October 2016, 11:28
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>
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>