PDA

View Full Version : Export StandardItemModel to XML



homerun4711
22nd December 2010, 10:45
Hi!

I need to export a QStandardModelItem to an XML-File.


QStandardItemModel *mod;
//put stuff inside

//then walk through the childs using

QStandardItem * item = mod->invisibleRootItem();
exportChild(item,out) ;

//writing the XMLFile using recursion of exportChild()

exportChild()
{
if (item->hasChildren())
...
exportChild(item,out)

}


Is this the best way to do that or is there an easier or better solution?

Kind regards,
HomeR

Lykurg
22nd December 2010, 10:52
Recursion sounds good. But I would write two functions above like and "hide" the child function.

bool saveQStandardItemModelToFile(QStandardItemModel, "filename");
QStandardItemModel* getQStandardItemModelOutOfFile("filename");

The absolutely best way would be to write a custom model which works direct with the xml file, but that is a quite a lot of work and for a small case it might be overkill.

homerun4711
23rd December 2010, 08:10
Thank you, this sounds good. I wil capsule the details and write a clean class to export the model.