PDA

View Full Version : QDom Issues



ToddAtWSU
20th June 2013, 20:29
I am trying to write an XML file using QDomDocument. I have written files before with no issues, but I am trying something differently this time and am experiencing issues with this. I have a main application where I create the QDomDocument and fill in all the over-arching Metadata. I then have a library utility that is trying to write out QDomDocumentFragments to be added to the QDomDocument.

So my heirarchy looks like this:

Application creates QDomDocument --> calls container library to get QDomDocumentFragments --> container calls each item in the container which creates its own QDomDocumentFragment

The container gathers all these Fragments into a QList and returns that to the application calling function which then loops through the list and appends these fragments onto the root node of the QDomDocument.

The code is on a stand-alone network which is why I am not including it on here. If I need to, to help figure this problem out I will take the time to type it all in.

So my application calls:


QList<QDomDocumentFragment> trackFrags = container->toXml( );

The container creates this QList<QDomDocumentFragment> and loops through each track object stored in the container calling its own toXml function.

It is inside this function where I have my issues. The code looks like something like:


QDomDocumentFragment frag;

QDomElement featureElem;
featureElem.setTagName( "Feature" );
frag.appendChild( featureElem );

QDomElement secondElem;
secondElem.setTagName( "Second" );
featureElem.appendCHild( secondElem );

I keep getting messages printing to my terminal window saying "Cannot append a child to a NULL node" or something real similar to that. So is there a way to do what I want to do without having to pass the QDomDocument down to these library classes? My hope was the library had to know nothing about the QDomDocument created by the application, but just create some fragments that could be passed from the library to the application and added to the document.

This is just a stub of what I am trying to do which is why it looks like it contains no meat. Also, I am using Qt 4.7 on Solaris 10.

Thanks for any help you have!
Todd

anda_skoa
21st June 2013, 08:12
I think you have to use QDomDocument::createElement() to create appendable elements.

What you could try is to use a local QDomDocument instance instead of passing in the actual one.

Cheers,
_

ToddAtWSU
21st June 2013, 13:10
I will give the try with a local QDomDocument. Unfortunately there are no static members for QDomDocument so we'll see if the local document works or if I need to pass it in.

Thanks!