Given a QDomElement, is there a way to obtain the QDomDocument that created it?
The first reason I ask is that when writing functions to generate DOM nodes, I always have to pass the QDomDocument to those functions as well in order to use it to create new elements, e.g.:
// doc is needed to create child nodes, e.g.
parent.appendChild(child);
// ...
}
void SomeData::save (QDomElement &parent, QDomDocument &doc) const {
// doc is needed to create child nodes, e.g.
QDomElement child = doc.createElement(...);
parent.appendChild(child);
// ...
}
To copy to clipboard, switch view to plain text mode
But if there was a way to not have to pass the document, it would be a little more convenient and clean up my parameter lists a bit, e.g.:
parent.appendChild(child);
// ...
}
void SomeData::save (QDomElement &parent) const {
QDomElement child = ???.createElement(...);
parent.appendChild(child);
// ...
}
To copy to clipboard, switch view to plain text mode
The second reason is that being able to do this with one function parameter would also lets me more easily do things like overload << and such, e.g.
QDomElement & operator << (QDomElement &parent, const SomeData &data);
To copy to clipboard, switch view to plain text mode
Bookmarks