[SOLVED] How to link two QML files using XMLListModel?
-
Okay. Let me try to be clear here.
"Attachment":http://i214.photobucket.com/albums/cc71/honeyhong/Capture.jpg
For example, I have a list as such, and the data (a list of array) are retrieved from an XML file.
Each of the data is supposed to be linked to its own respective page.Right now, when onClicked, I could link to other page, but as a whole. Meaning when i click any data, it will all link to the same page.
I want to click on the data individually (the yellow area) and each link to its own page.I couldn't preset a name for each of the data in list element and call it, because since these data are retrieved from a XML file,
it will always be updated and the amount of data may change every time it is updated.Anyone can tell me how to do it?
I hope I am clear. Really need some solution.
-
Define an onClicked handler for each delegate, which uses data passed to it by the model (ie, attached property or whatever). Each item in the model will have separate links/array data, I assume.
-
[quote author="chriadam" date="1341980227"]Define an onClicked handler for each delegate, which uses data passed to it by the model (ie, attached property or whatever). Each item in the model will have separate links/array data, I assume.[/quote]
Got it. Solved.
Thank you for your tips. :)For reference, here are my codes :
//page1
@
import QtQuick 1.1
import com.nokia.symbian 1.1
import "../js/Util.js" as Util
import "../delegates"Page {
id: container
property string itemTitle: ""
signal feedItemSelected(string title)XmlListModel { id: test1 property string feedUrl: "" property bool loading: status == XmlListModel.Loading source: "http:// (put in the url)" query: "/plist/array/dict" XmlRole { name: "details"; query: "string[1]/string()" }
}
ListView { id: list1 anchors { left: parent.left right: parent.right top: headBar.bottom bottom: parent.bottom } clip: true model: test1 delegate: listDelegate1 } Component { id: listDelegate1
//settings of the details to be displayed in TestItem.qml
TestItem
{ text1: details
onClicked:
{
Util.log("Clicked ....on " + details)
container.itemTitle = details
feedItemSelected(details)onFeedItemSelected: { Util.log("Selected feed item"); pageStack.push(feedItemView); } }
//link to page 2
Page2 {
id: feedItemView
width: parent.width
itemTitle: container.itemTitle
}
}
}
@I have another file which are placed in the same folder that defines the settings of the text to be displayed in Page 1 called TestItem1.qml
@
//TestItem.qml
import QtQuick 1.1
import "../js/Util.js" as UtilItem {
id: container
property string text1: "DETAILS"signal clicked width: parent.width height: Math.max(54, itemText1.itemTextHeight) clip: true
Text {
id: itemText1
property int itemTextHeight: height + anchors.topMargin + anchors.bottomMargin
text: container.text1}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: container.clicked();}
}
@solved. thanks for your help :)