0

如何使用 qt 将其写入 xml 文件?

 <model>
  <column loop="true">`enter code here`
    <item2  color="#4d6862"  />
    <item2  color="#ff0000ff" />
    <item2  color="#ff00ff00" />
    <item2 color="#ff00ffff" />
    <item2 color="#ffff0000" />
    <item2 color="#ffff00ff" />
    <item2  color="#ffffff00" />
    <item2 color="#4d6862" />
  </column>
</model>

这看起来很有希望(在 QtXML (QDomElement) 中编写 XML 节点),但它没有提到属性。

4

1 回答 1

0

你可以这样做:http QXmlStreamWriter: //qt-project.org/doc/qt-5/qxmlstreamwriter.html

QXmlStreamWriter writer (&file);    // a QFile object, must be open for writing
writer.setAutoFormatting(true);
writer.writeStartDocument("1.0");
writer.writeStartElement ("model");
writer.writeStartElement ("column");
    writer.writeAttribute ("loop", "true");

    writer.writeStartElement ("item2");
    writer.writeAttribute ("color", "#4d6862");
    writer.writeEndElement ();
    // write all other items

writer.writeEndDocument();   // this will close all open tags
于 2014-01-28T07:56:49.123 回答