01-18-2013 08:31 AM
Hi there!
There is a way to iterate the XmlDataModel using C++???
Thanks!
01-18-2013 09:03 AM
Use XmlDataModel::childCount(QVariantList) to obtain the child count for a particular indexPath.
Every indexPath is a QVariantList of int's, each int being an index. The empty indexPath will be the path to the root element.
So:
QVariantList path;
qDebug() << xmlDataModel.childCount(path);
will output the number of child elements.
You can retrieve the elements with:
XmlDataModel::data(QVariantList)
01-18-2013 09:22 AM
Which QVariantList parameter should I need to set? If I wanna see all the elements for instance? it is not very clear for me how it should be according to the documentation:
https://developer.blackberry.com/cascades/referenc
01-18-2013 09:55 AM
Well, it's a tree structure (an XML document), so if your indexPath has no elements:
[]
then childCount will return the number of root nodes in your document (which it turns out is the number of elements beneath the root node):
<root>
<item>One</item>
<item>Two</item>
<item>Three<subitem>A</subitem></item>
</root>
So :
QVariantList path;
// path is empty []
m_model->childCount(path); // returns 3 - 3 items
path.append(QVariant(2));
m_model->data(path); // returns QVariantMap for item Three
I've not actually played with going deeper, but in theory:
path.append(0);
m_model->data(path); // returns QVariantMap for subitem A
In the last case, path now has [2,0] as the indexPath.
Easiest is to play around with this and use qDebug() to see what it does.
01-18-2013 02:57 PM
It works ![]()
But I can not change the data.... do you know how to change the data in the model?? for instance, the item
<item>One</item>
I wnat to change it for :
<item> this is the one </item>