tags:

views:

162

answers:

1

I'm using qt 4.4.3 with c++. I want to implement a QDomDocumentFragment object, and pass it as a return value for a function. I am using it the same way as QDomElement objects, with appendChild():

QDomDocumentFragment rootnode;

QDomNode initmodnode = doc.createElement("initmod");
QDomText initmodval = doc.createTextNode("4");
initmodnode.appendChild(initmodval);
rootnode.appendChild(initmodnode);

After inserting 7 other nodes in this way, and returning from the function, I noticed that calling insertAfter() on a QDomElement node with the returned QDomDocumentFragment was not inserting any new children. After debugging with the following code inside the function, I realized no nodes were actually getting inserted into rootnode:

QMessageBox::information(this->owner, QObject::tr("Debug"), QObject::tr("Node has children: ")+QString::number(rootnode.childNodes().size()));

The Message printed was "Node has children: 0". What am I missing here?

+1  A: 

Ok sorry for wasting everyone's time.. looks like I needed to create the document fragment using:

QDomDocumentFragment rootnode = doc.createDocumentFragment();
Alpants