1 #include "widget.h"
2 #include "ui_widget.h"
3 #include
4 #include
5 #include
6
7 Widget::Widget(QWidget *parent) :8 QWidget(parent),9 ui(newUi::Widget)10 {11 ui->setupUi(this);12
13 QString file_path = "../demo.xml";14
15 create_xml(file_path);16
17 QStringList list;18 //姓名 性别 年龄 学课 分数
19 list << "xiaoming" << "male" << "19" << "Chinese" << "78";20 append_xml(file_path, 1, list);21 list.clear();22 list << "xiaohong" << "famale" << "18" << "Math" << "88";23 append_xml(file_path, 2, list);24 list.clear();25 read_xml(file_path, 2, list);26 qDebug() <
29 Widget::~Widget()30 {31 deleteui;32 }33
34 /*
35 * 创建xml文件,空文件,仅包含头部信息和根元素节点36 * 参数file_path:文件存放路径37 */
38 voidWidget::create_xml(QString file_path)39 {40 QFile file(file_path); //关联文件名字
41 if (true == file.exists()) { //如果存在不创建
42 qDebug() << "文件已经存在";43 return;44 }45 //只写方式打开文件
46 bool isOK =file.open(QIODevice::WriteOnly);47 if (false ==