http://www.qter.org/portal.php?mod=view&aid=62
一、新建QT控制檯應用,在.pro中添加
QT += core xmlphp
二、源碼修改code
#include <QCoreApplication> #include <QtXml> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QFile file("my.xml");//創建指向my.xml文件的QFile對象. if(!file.open(QFile::WriteOnly | QFile::Text)) //以文本方式,只讀打開文件 { qDebug() << "打開失敗"; return -1; } QXmlStreamWriter stream(&file); stream.setAutoFormatting(true); stream.writeStartDocument(); stream.writeStartElement("bookmark"); stream.writeAttribute("href", "http://qt.io/"); stream.writeEndElement(); stream.writeEndDocument(); file.close(); qDebug() << "寫入完成"; return a.exec(); }
寫入不成功:orm
寫入成功xml