Hi everybody,

I'm developing a little 2d Graphics Modeling application using the Qt's Graphics View framework. Currently, I'm trying to find out how to Save and Load the state of a Scene.
I've been advised to store the data as an XML archive. So I thought I would just iterate over my QGraphicsScene's items gettin its properties and storing them with an appropriate tagging, like for example for an ellipse :

Qt Code:
  1. <elipse id="ellipse1">
  2. <color> Black </color>
  3. <width>50</width>
  4. <height>50</height>
  5. </ellipse>
To copy to clipboard, switch view to plain text mode 

After reading that I would create a QGraphicsEllipseItem with a Black contour bounded by a 50x50 rectangle and add it to the current scene that is being loaded. For storing I would iterate over the Scene's elements, get its properties and store it like the code above.

But I'm facing a little problem with the iteration over the tags using readNextStartElement() . Here's my main loop code:

Qt Code:
  1. //parser is a QXmlStreamReader object
  2. while(!parser.isEndDocument()){
  3.  
  4. while(parser.readNextStartElement()){
  5.  
  6. if(parser.name() == "ellipse"){ //When it finds an <ellipse> tag
  7. readEllipse();
  8. }
  9. else{
  10. continue;
  11. }
  12.  
  13. }
  14. }
To copy to clipboard, switch view to plain text mode 

And the code for function readEllipse() :
Qt Code:
  1. void MyXmlReader::readEllipse(){
  2.  
  3. QGraphicsEllipseItem *newEllipse = new QGraphicsEllipseItem(); //Creates a new Ellipse which will later be added to the scene
  4.  
  5. while(parser.readNextStartElement()){ //Should read all the tags untill </ellipse> is reached, so it can call appropriate readColor(),readHeight(),etc.
  6. // readColor() or readHeight() or readWidth()
  7. }
  8.  
  9. //Here all the properties of the ellipse would have already been parsed so we could add it to the actual scene:
  10. parentQGraphicsScene->addItem( newEllipse);
  11.  
  12. }
To copy to clipboard, switch view to plain text mode 

The problem with this approach is that when I call readNextStartElement() in the main loop, I read the <ellipse> tag and then readEllipse() is called. Inside readEllipse(), the while(parser.readNextStartElement) starts reading <color> and keeps reading until it finds its end tag (i.e </color>) and so it stops, leaving the processing of <height> and <width> undone.

If it had a way to know wether I'm still inside <ellipse></ellipse> I guess I could just keep reading next start element untill it finds </ellipse> .

I'm a litle confused here since it's my first time parsing a XML file, so if could somebody help me figure this out, suggesting a simpler approach perhaps, I would be very grateful.

Thanks in advance,
Luiz.