PDA

View Full Version : Could anyone show me the Model



Xagen
17th March 2006, 20:53
Hi! Can anyone show me the example of model which should work with reading from xml file:
for exaple, my app reads one xml file and need to insert the data to the model...

How can I do it?

Thanks for advices! (Documentation I've read) but there is one problem - xml parser and wodel - how to connect?

wysota
17th March 2006, 22:33
You don't have to "insert" anything into a model. The xml file can be a model... You ask for an example... I can't give you an example of a complete model, this is your job. I can give you a hint -- use DOM (QDomDocument and family) to parse xml file and provide data for your model. Another hint would be to state, that probably internal pointers that come in idexes should point to appropriate QDomElements.

Chicken Blood Machine
17th March 2006, 23:49
You don't have to "insert" anything into a model. The xml file can be a model... You ask for an example... I can't give you an example of a complete model, this is your job. I can give you a hint -- use DOM (QDomDocument and family) to parse xml file and provide data for your model. Another hint would be to state, that probably internal pointers that come in idexes should point to appropriate QDomElements.

That's easier said than done. See here : http://lists.trolltech.com/qt4-preview-feedback/2005-03/thread00810-0.html

You may find that you will have to parse the XML file with QDomDocument and create your own persistant tree structure to store the data that you read for your model. You can then safely have your model indexes point to items in this data structure.

[EDIT]
Alternatively, as you load your QDomDocument, store all the data in a QStandardItemModel. I think this option would be easiest to implement, since you wont have to worry about using QModelIndexes at all.