Hi,
please explain what is wrong with my code:
#include <QDomDocument>
#include <QFile>
int main(int argc, char *argv[])
{
QFile file("c:\\bugtest.xml");
doc.setContent(&file);
file.close();
while(!n.isNull()) {
QDomElement e
= n.
toElement();
// try to convert the node to an element. if(!e.isNull()) {
if (e.tagName() == "value" && e.hasAttribute("id"))
{
} /* crash point */
n = n.nextSibling();
}
}
}
#include <QDomDocument>
#include <QFile>
int main(int argc, char *argv[])
{
QDomDocument doc;
QFile file("c:\\bugtest.xml");
file.open(QIODevice::ReadOnly);
doc.setContent(&file);
file.close();
QDomElement docElem = doc.documentElement();
QDomNode n = docElem.firstChild();
while(!n.isNull()) {
QDomElement e = n.toElement(); // try to convert the node to an element.
if(!e.isNull()) {
if (e.tagName() == "value" && e.hasAttribute("id"))
{
QString id = e.attribute("id");
QString data = e.text();
} /* crash point */
n = n.nextSibling();
}
}
}
To copy to clipboard, switch view to plain text mode
The code crashes at the point marked, when deleting QString data - heap corrupted.
The document is:
<?xml version="1.0" encoding="utf-8"?>
<data>
<value id="some_id">Some value</value>
</data>
<?xml version="1.0" encoding="utf-8"?>
<data>
<value id="some_id">Some value</value>
</data>
To copy to clipboard, switch view to plain text mode
Windows XP, Visual studio 2005, QT 4.5.0-rc1 (also 4.3.5).
Thanks in advance.
Bookmarks