我想用Qt写和读一个xml文件。有没有一个简单的示例代码,可以动态生成XML文件?
我发现了一些Qt xml类,但有谁知道它们是用来做什么的,有没有使用这些类的简单示例?
QtXml Module (http://doc.qt.nokia.com/latest/qtxml.html)
QXmlStreamReader (http://doc.qt.nokia.com/4.7/qxmlstreamreader.html)
QXmlStreamWriter (http://doc.qt.nokia.com/4.7/qxmlstreamreader.html)我已经编写了一个托管C++代码,但我的问题是该代码(需要使用/clr )在Visual Studio2010中不支持IntelliSense。现在我试着找到另一种选择。如果任何人知道一些功能几乎相同的东西,只使用非托管代码,那将是完美的!
此外,我找到了这个,但不知道如何使用它:QString to XML in QT
发布于 2011-08-02 20:44:41
谢谢你的回答!
我在诺基亚找到了这些使用QT生成和读取XML文件的链接:
编写XML文件:http://developer.nokia.com/community/wiki/Generate_XML_programatically_in_Qt
读取XML文件:http://www.developer.nokia.com/Community/Wiki/Using_QXmlStreamReader_to_parse_XML_in_Qt
下面是在写入和读取XML文件时使用的QT类:
http://doc.qt.nokia.com/4.7/qxmlstreamwriter.html
http://doc.qt.nokia.com/4.7/qxmlstreamreader.html
发布于 2011-08-01 22:29:19
如果你打算解析小的xml文件,最简单的方法是使用QDomDocument类,参见下面的示例,取自“用Qt4进行C++图形用户界面编程,第二版”。
QFile file(filename);
QString errorStr;
int errorLine;
int errorColumn;
QDomDocument doc;
if (!doc.setContent(&file, false, &errorStr, &errorLine,
&errorColumn)) {
std::cerr << "Error: Parse error at line " << errorLine << ", "
<< "column " << errorColumn << ": "
<< qPrintable(errorStr) << std::endl;
return false;
}
QDomElement root = doc.documentElement();
if (root.tagName() != "bookindex") {
std::cerr << "Error: Not a bookindex file" << std::endl;
return false;
}但是,整个xml都保存在内存中,因此要小心处理大型xml文件。
https://stackoverflow.com/questions/6898567
复制相似问题