I have a little problem with passing a QDomDocument pointer recursive.
Maybe you can tell me what I’ve overlooked.
QString Node::asXML()
{
QDomDocument *doc = new QDomDocument();
QDomElement ele = doc->createElement(typeInfo());
doc->appendChild(ele);
foreach (Node *child, children)
{
qDebug() << "Node: " << child->name;
child->recurseXML(doc, ele);
}
return doc->toString();
}
void Node::recurseXML(QDomDocument *doc, QDomElement parent)
{
QDomElement node = doc->createElement(typeInfo());
parent.appendChild(node);
QMapIterator<QString, QVariant> i(attributes);
qDebug() << attributes.size();
while(i.hasNext())
{
i.next();
node.setAttribute(i.key(), i.value().toString());
qDebug() << "KEY: " << i.key() << " | VALUE: " << i.value().toString();
}
}
I loose the data that i get from the recursion, but I’m not sure why. Probably I’ve done a pointer mistake but I dont see it. Maybe someone can help me
Regards
In the recurseXML function the parameter parent is a local variable. It is not the same QDomElement you created in the asXML function but a copy of it. Change parent to a reference or a pointer:
–>