在VS2012中使用QT5.1,加载QtXml来操作xml档。可是出了一个很奇怪的问题。下面是实现代码
#include "XmlTest.h"
#include <QtDebug>
void XmlTest::write()
{
QDomDocument document;
QDomElement d=document.createElement("document");
d.setAttribute("name","DocName");
QDomElement a=document.createElement("author");
a.setAttribute("name","AuthorName");
QDomText text=document.createTextNode("Some text");
document.appendChild(d);
d.appendChild(a);
d.appendChild(text);
QFile file("simple.xml");
if (!file.open(QIODevice::WriteOnly|QIODevice::Text))
{
qDebug("Failed to open file for writing.");
return;
}
QTextStream stream(&file);
stream<<document.toString();
file.close();
}在编译时,出现以下错误

在VS2012中使用QT5.1进行XML操作时遇到内部异常。问题在于QDomNode和QDomDocument,可能原因包括头文件未实现或未正确链接库。首先尝试将Qt5Xml.lib添加到链接器,解决了编译问题,但运行时仍出现内部错误。最终发现应使用Qt5Xmld.lib而非Qt5Xml.lib,修改后程序正常运行并成功生成XML文件。

3299

被折叠的 条评论
为什么被折叠?



