Here is my line of code where I want to load source:
data from xml file which is located in my device shared folder.
The path of that xml file is QFile textfile("/accounts/1000/shared/documents/myData.xml");
My code is:
import bb.cascades 1.0
import bb.data 1.0
Page {
content: ListView {
id: listView
dataModel: dataModel
...
}
attachedObjects: [
GroupDataModel {
id: dataModel
},
DataSource {
id: dataSource
//---------------------------------------
//Here I want to load xml file
//---------------------------------------
source: "/accounts/1000/shared/documents/myData.xml"
//---------------------------------------
query: "/contacts/contact"
onDataLoaded: {
dataModel.insertList(data);
}
}
]
onCreationCompleted: { dataSource.load(); }
}
Anyone please help me, how exactly load xml file in GroupDataModel which is located in above device directory location.
Thanks in advance.
we have two parts to do this :
First one allowing your application to use shared folders
Steps:
Second one is Get the correct path using C++ and send it to Qml in context property
This in your ApllicationUI.cpp C++ Code
// Build the path, add it as a context property, and expose
// it to QML
QString workingDir = QDir::currentPath();
QString path = "file://" + workingDir +"/shared/documents/model.xml";
QDeclarativePropertyMap* dirPaths = new QDeclarativePropertyMap;
dirPaths->insert("documents", QVariant(QString(path)));
qml->setContextProperty("dirPaths", dirPaths);
QML
dataModel: XmlDataModel {
source: dirPaths.documents
}