加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.cpp 8.69 KB
一键复制 编辑 原始数据 按行查看 历史
箜栢 提交于 2020-03-02 09:14 . 第一次提交
#include "mainwindow.h"
#include <QApplication>
#include <QDomDocument>
#include "MyApplication.h"
#include "XmlDataDoc.h"
#include "XmlDataUnit.h"
#include "dXml.h"
#include <QDir>
#include <qfile.h>
#include <QFileInfo>
/*
bool userXmlStream( ) {
QString filepath = QDir::currentPath( ) + "/debugXmlDemo001/xmlFile2.xml";
QFileInfo info(filepath);
QDir dir;
dir.mkpath(info.absolutePath( ));
QFile file(filepath);
if( !file.open(QFile::WriteOnly | QFile::Text | QFile::Truncate) ) {
qDebug( ) << "failed to open bg_train01.xml";
return true;
}
QXmlStreamAttributes attributes;
QXmlStreamWriter writer;
writer.setCodec("UTF-8");
writer.setDevice(&file);
writer.setAutoFormatting(true);
writer.writeStartDocument( ); //编写文档的第一行
writer.writeStartElement("ConfigInfo");
writer.writeComment("开始保存第1行的配置数据!");
writer.writeStartElement("RootDir");
attributes.append("itemText", "BG-HAO(2873/2873)");
attributes.append("dirBaseName", "BG-HAO");
attributes.append("withSubDir", "false");
attributes.append("showSubDir", "false");
writer.writeAttributes(attributes);
writer.writeStartElement("SubDir");
attributes.clear( );
attributes.append("itemText", "/");
attributes.append("dirBaseName", "BG-HAO");
attributes.append("withSubDir", "false");
attributes.append("showSubDir", "false");
writer.writeAttributes(attributes);
writer.writeTextElement("ImageSum", "2873");
writer.writeEmptyElement("DirInfo");
attributes.clear( );
attributes.append("dirFullName", "/home/liuqiang/Documents/BG/train/BG-HAO");
attributes.append("imageNumber", "2873");
writer.writeAttributes(attributes);
writer.writeTextElement("Weight", "1.0");
writer.writeEmptyElement("Label");
attributes.clear( );
attributes.append("name", "(0)hao");
attributes.append("color", "#12ec76");
attributes.append("number", "0");
writer.writeAttributes(attributes);
writer.writeEndElement( );
writer.writeEndElement( );
writer.writeComment("第1行的配置数据保存完毕!");
writer.writeComment("开始保存第2行的配置数据!");
writer.writeStartElement("RootDir");
attributes.clear( );
attributes.append("itemText", "BG-CHA(4222/4222)");
attributes.append("dirBaseName", "BG-CHA");
attributes.append("withSubDir", "false");
attributes.append("showSubDir", "false");
writer.writeAttributes(attributes);
writer.writeStartElement("SubDir");
attributes.clear( );
attributes.append("itemText", "/");
attributes.append("dirBaseName", "BG-CHA");
attributes.append("withSubDir", "false");
attributes.append("showSubDir", "false");
writer.writeAttributes(attributes);
writer.writeTextElement("ImageSum", "4222");
writer.writeEmptyElement("DirInfo");
attributes.clear( );
attributes.append("dirFullName", "/home/liuqiang/Documents/BG/train/BG-CHA");
attributes.append("imageNumber", "4222");
writer.writeAttributes(attributes);
writer.writeTextElement("Weight", "1.0");
writer.writeEmptyElement("Label");
attributes.clear( );
attributes.append("name", "(1)cha");
attributes.append("color", "#0cc8f3");
attributes.append("number", "1");
writer.writeAttributes(attributes);
writer.writeEndElement( );
writer.writeEndElement( );
writer.writeComment("第2行的配置数据保存完毕!");
writer.writeComment("开始保存第3行的配置数据!");
writer.writeStartElement("RootDir");
attributes.clear( );
attributes.append("itemText", "train(7095/7095)");
attributes.append("dirBaseName", "train");
attributes.append("withSubDir", "true");
attributes.append("showSubDir", "false");
writer.writeAttributes(attributes);
writer.writeStartElement("SubDir");
attributes.clear( );
attributes.append("itemText", "/");
attributes.append("dirBaseName", "train");
attributes.append("withSubDir", "true");
attributes.append("showSubDir", "false");
writer.writeAttributes(attributes);
writer.writeTextElement("ImageSum", "7095");
writer.writeEmptyElement("DirInfo");
attributes.clear( );
attributes.append("dirFullName", "/home/liuqiang/Documents/BG/train/BG-HAO");
attributes.append("imageNumber", "2873");
writer.writeAttributes(attributes);
writer.writeEmptyElement("DirInfo");
attributes.clear( );
attributes.append("dirFullName", "/home/liuqiang/Documents/BG/train/BG-CHA");
attributes.append("imageNumber", "4222");
writer.writeAttributes(attributes);
writer.writeTextElement("Weight", "1.0");
writer.writeEmptyElement("Label");
attributes.clear( );
attributes.append("name", "(0)hao");
attributes.append("color", "#12ec76");
attributes.append("number", "0");
writer.writeAttributes(attributes);
writer.writeEndElement( );
writer.writeEndElement( );
writer.writeComment("第3行的配置数据保存完毕!");
writer.writeComment("开始保存第4行的配置数据!");
writer.writeStartElement("RootDir");
attributes.clear( );
attributes.append("itemText", "train(7095/7095)");
attributes.append("dirBaseName", "train");
attributes.append("withSubDir", "true");
attributes.append("showSubDir", "true");
writer.writeAttributes(attributes);
writer.writeStartElement("SubDir");
attributes.clear( );
attributes.append("itemText", "BG-HAO(2873/2873)");
attributes.append("dirBaseName", "BG-HAO");
attributes.append("withSubDir", "false");
attributes.append("showSubDir", "false");
writer.writeAttributes(attributes);
writer.writeTextElement("ImageSum", "2873");
writer.writeEmptyElement("DirInfo");
attributes.clear( );
attributes.append("dirFullName", "/home/liuqiang/Documents/BG/train/BG-HAO");
attributes.append("imageNumber", "2873");
writer.writeAttributes(attributes);
writer.writeTextElement("Weight", "1.0");
writer.writeEmptyElement("Label");
attributes.clear( );
attributes.append("name", "(1)cha");
attributes.append("color", "#0cc8f3");
attributes.append("number", "1");
writer.writeAttributes(attributes);
writer.writeEndElement( );
writer.writeStartElement("SubDir");
attributes.clear( );
attributes.append("itemText", "BG-CHA(4222/4222)");
attributes.append("dirBaseName", "BG-CHA");
attributes.append("withSubDir", "false");
attributes.append("showSubDir", "false");
writer.writeAttributes(attributes);
writer.writeTextElement("ImageSum", "4222");
writer.writeEmptyElement("DirInfo");
attributes.clear( );
attributes.append("dirFullName", "/home/liuqiang/Documents/BG/train/BG-CHA");
attributes.append("imageNumber", "4222");
writer.writeAttributes(attributes);
writer.writeTextElement("Weight", "1.0");
writer.writeEmptyElement("Label");
attributes.clear( );
attributes.append("name", "(1)cha");
attributes.append("color", "#0cc8f3");
attributes.append("number", "1");
writer.writeAttributes(attributes);
writer.writeEndElement( );
writer.writeEndElement( );
writer.writeComment("第4行的配置数据保存完毕!");
writer.writeEndElement( );
file.close( );
return false;
}
*/
void test( ) {
//if( userXmlStream( ) )
// return;
dXml::XmlDataDoc myDoc;
QDomProcessingInstruction instruction; //添加处理命令
QString text = "猪头以";
QString nodeName = "节点";
dXml::XmlDataUnit* unit = new dXml::XmlDataUnit(nodeName);
myDoc.appendChildren(unit);
QString attr = "沙嗲";
QString value = "250";
unit = new dXml::XmlDataUnit(nodeName);
myDoc.appendChildren(unit);
myDoc.appendAttr(attr, value);
text = "你好";
myDoc.setName(text);
QDomDocument qDomDocument;
//unit->appendComment(QStringList() << "注释一个试试");
instruction = qDomDocument.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
qDomDocument.appendChild(instruction);
unit = new dXml::XmlDataUnit(nodeName);
unit->setText("若干");
myDoc.appendChildren(unit);
auto string = QDir::currentPath( ) + "/debugXmlDemo001/xmlFile.xml";
myDoc.save(string);
myDoc.clear( );
QString piTaget;
QString piData;
dXml::readXmlFile(&myDoc, piTaget, piData, string);
myDoc.save(QDir::currentPath( ) + "/debugXmlDemo001/copy.xml");
myDoc.clear( );
dXml::readXmlFile(&myDoc, piTaget, piData, QDir::currentPath( ) + "/debugXmlDemo001/xmlFile2.xml");
myDoc.save(QDir::currentPath( ) + "/debugXmlDemo001/copy2.xml");
dXml::XmlDataDoc buff1 = myDoc;
dXml::XmlDataDoc buff2 = myDoc;
dXml::XmlDataDoc buff3 = myDoc;
dXml::XmlDataDoc buff4 = myDoc;
myDoc.save(QDir::currentPath( ) + "/debugXmlDemo001/buff0.xml");
buff1.save(QDir::currentPath( ) + "/debugXmlDemo001/buff1.xml");
buff2.save(QDir::currentPath( ) + "/debugXmlDemo001/buff2.xml");
buff3.save(QDir::currentPath( ) + "/debugXmlDemo001/buff3.xml");
buff4.save(QDir::currentPath( ) + "/debugXmlDemo001/buff4.xml");
myDoc = dXml::XmlDataDoc( );
}
int main(int argc, char* argv[]) {
/*test( );
return 0;*/
MyApplication myAppRun(argc, argv);
widgetUI::MainWindow* mainWindow = new widgetUI::MainWindow;
myAppRun.setWinProcessing(mainWindow);
mainWindow->show( );
int execResult;
execResult = myAppRun.exec( );
return execResult;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化