Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I append children to QDomDocumentFragment object in qt with c++

Tags:

c++

qt

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?

like image 273
Alpants Avatar asked Oct 23 '25 01:10

Alpants


1 Answers

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

QDomDocumentFragment rootnode = doc.createDocumentFragment();
like image 82
Alpants Avatar answered Oct 25 '25 16:10

Alpants



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!