Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
4.7.3
-
None
-
Windows 7
Visual C++ 2010 Express
Description
The QDomDocument::setContent implementation reuses an existing QDomDocumentPrivate. This is a problem for nodes of the "old" document.
Example code:
QDomNode node; QDomNode::NodeType type; QString string;
{
QDomDocument doc;
node = doc.appendChild(doc.createElement("element"));
type = node.parentNode().nodeType(); // == DocumentNode
string = node.ownerDocument().toString(); // == "<element/>"
doc.setContent(QString("<other/>"));
type = node.parentNode().nodeType(); // == DocumentNode
string = node.ownerDocument().toString(); // == "<other/>" (but node has not been changed)
}
type = node.parentNode().nodeType(); // throws access violation
Our current workaround to have no crash is:
QDomNode node; QDomNode::NodeType type; QString string;
{
QDomDocument doc;
node = doc.appendChild(doc.createElement("element"));
type = node.parentNode().nodeType(); // == DocumentNode
string = node.ownerDocument().toString(); // == "<element/>"
doc = QDomDocument(); // currently needed to get no access violation
doc.setContent(QString("<other/>"));
type = node.parentNode().nodeType(); // == BaseNode
string = node.ownerDocument().toString(); // == ""
}
type = node.parentNode().nodeType(); // == BaseNode (throws no exception)
So with our workaround we get no access violation but can not access the ownerDocument after calling setContent.