01-12-2013 04:51 PM - edited 01-12-2013 04:53 PM
Hi,
I would like to know how to save a list item using the XmlDatamodel into another xml file.
Thanks.
01-12-2013 09:42 PM
This doesn't seem to be possible.
You'll have to extract the data item by item and write it to the file using QXmlStreamWriter or some other class.
QFile file(filename);
file.open(QIODevice::WriteOnly);
QXmlStreamWriter xmlWriter(&file);
xmlWriter.setAutoFormatting(true);
xmlWriter.writeStartDocument();
xmlWriter.writeStartElement("ELEMENT");
xmlWriter.writeStartElement("SUBELEMENT");
xmlWriter.writeTextElement("State", "state");
xmlWriter.writeEndElement();
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
file.close();
Another way is to implement your custom datamodel to perform both XML parsing and saving. This is a cleaner approach but harder to implement.
01-13-2013 06:17 PM
Thanks for the response. this is what I have. This what I tried based on your reply can you please advise.
import bb.cascades 1.0
Page {
actions: [
// create navigation panel actions here
ActionItem {
title: qsTr("Create a report")
onTriggered: {
imgView.imageSource = "asset:///images/picture1br.png"
}
}
]
Container {
id: listCt
// the childcount for the list item
property alias listChildCount: chList.childCount
property alias radioSelection: radioGp.selectedIndex
ListView {
id: chList
dataModel: XmlDataModel {
source: "models/Chapter2.xml"
}
listItemComponents: [
ListItemComponent {
type: "header"
Header {
title: ListItemData.title
}
},
ListItemComponent {
type: "listItem"
Container {
layout: DockLayout {}
LabelLabel {
text: ListItemData.title
bottomPadding: 50.0
leftPadding: 150.0
}// end of LabelLabel
RadioGroup {
id: radioGp
dividersVisible: false
preferredWidth: 150
minWidth: 149.0
Option {
id: option1
text: "H"
}
Option {
id: option2
text: "M"
}
Option {
id: option3
text: "L"
}
// When a new option is selected, we print the selection to the console.
onSelectedValueChanged: {
console.debug("New filling set: " + selectedValue);
if(selectedIndex >= 0) {
radioIndex = radioGp.selectedIndex
}//endif
}//end onSelected
}//end radioGroup
Divider {} // at the end of each list item
} // end of Container
} // end of second ListItemComponent
] // end of listItemComponents list
// When an item is selected, update the text in the TextField
// to display the status of the new item
onTriggered: {
var selectedItem = dataModel.data();
var page = getSecondPage();
secondPage.xmlWriter.setAutoFormatting(true);
seondPage.writeStartDocument();
seconPage.xmlWriter.writeStartElement(selectedItem );
xmlWriter.writeTextElement("State", radioIndex);
xmlWriter.writeEndElement();
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
file.close();
}// end onTriggered
property Page secondPage
function getSecondPage() {
if (! secondPage) {
secondPage = reportFile.createObject();
}
return secondPage;
}
attachedObjects: [
ComponentDefinition {
id: reportFile
source: "../models/report.qml"
}
]
} // end of ListView
}
}Thx