JasonC
5th March 2015, 18:44
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.:
void SomeData::save (QDomElement &parent, QDomDocument &doc) const {
// doc is needed to create child nodes, e.g.
QDomElement child = doc.createElement(...);
parent.appendChild(child);
// ...
}
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.:
void SomeData::save (QDomElement &parent) const {
QDomElement child = ???.createElement(...);
parent.appendChild(child);
// ...
}
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);
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.:
void SomeData::save (QDomElement &parent, QDomDocument &doc) const {
// doc is needed to create child nodes, e.g.
QDomElement child = doc.createElement(...);
parent.appendChild(child);
// ...
}
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.:
void SomeData::save (QDomElement &parent) const {
QDomElement child = ???.createElement(...);
parent.appendChild(child);
// ...
}
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);