Results 1 to 3 of 3

Thread: Export StandardItemModel to XML

  1. #1
    Join Date
    Oct 2010
    Posts
    91
    Thanks
    38

    Default Export StandardItemModel to XML

    Hi!

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

    Qt Code:
    1. //put stuff inside
    2.  
    3. //then walk through the childs using
    4.  
    5. QStandardItem * item = mod->invisibleRootItem();
    6. exportChild(item,out) ;
    7.  
    8. //writing the XMLFile using recursion of exportChild()
    9.  
    10. exportChild()
    11. {
    12. if (item->hasChildren())
    13. ...
    14. exportChild(item,out)
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

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

    Kind regards,
    HomeR

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Export StandardItemModel to XML

    Recursion sounds good. But I would write two functions above like and "hide" the child function.
    Qt Code:
    1. bool saveQStandardItemModelToFile(QStandardItemModel, "filename");
    2. QStandardItemModel* getQStandardItemModelOutOfFile("filename");
    To copy to clipboard, switch view to plain text mode 

    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.

  3. The following user says thank you to Lykurg for this useful post:

    homerun4711 (23rd December 2010)

  4. #3
    Join Date
    Oct 2010
    Posts
    91
    Thanks
    38

    Default Re: Export StandardItemModel to XML

    Thank you, this sounds good. I wil capsule the details and write a clean class to export the model.

Similar Threads

  1. Trying to export to Excel
    By ShamusVW in forum Qt Programming
    Replies: 7
    Last Post: 4th August 2010, 08:07
  2. Export widget to bmp
    By Lodhart in forum Newbie
    Replies: 1
    Last Post: 10th December 2009, 12:06
  3. how to export dll with gui?
    By cutie.monkey in forum Qt Programming
    Replies: 5
    Last Post: 14th November 2009, 02:19
  4. Export SVG: Qwt Bug?
    By giusepped in forum Qwt
    Replies: 4
    Last Post: 19th December 2008, 10:50
  5. Workaround for StandardItemModel drag drop bug
    By onamatic in forum Qt Programming
    Replies: 4
    Last Post: 9th November 2008, 21:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.