当前位置:   article > 正文

Qt读写XML文件_qt 写xml文件

qt 写xml文件

项目*.pro 里添加

QT += xml


1 写XML :  main.cpp

  1. #include <QtCore>
  2. #include <QDebug>
  3. #include <QtXml>
  4. int main(int argc, char *argv[])
  5. {
  6. QCoreApplication a(argc, argv);
  7. //Write XML
  8. QDomDocument document;
  9. //Make the root element
  10. QDomElement root =document.createElement("Books");
  11. //Add it to the documnet
  12. document.appendChild(root);
  13. //Add some elements
  14. for(int i =0;i<10;++i)
  15. {
  16. QDomElement book = document.createElement("Book");
  17. book.setAttribute("Name","My Book " +QString::number(i));
  18. book.setAttribute("ID",QString::number(i));
  19. root.appendChild(book);
  20. for(int h=0;h<10;h++)
  21. {
  22. QDomElement chapter = document.createElement("Chapter");
  23. chapter.setAttribute("Name","My Chapter " &#
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/781897
推荐阅读
相关标签
  

闽ICP备14008679号