加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

QT中对XML的处理

发布时间:2020-12-16 05:55:26 所属栏目:百科 来源:网络整理
导读:QT自带例子: C:QtQt5.5.1ExamplesQt-5.5widgetsitemviewssimpledommodelsimpledommodel.pro C:QtQt5.5.1ExamplesQt-5.5xmldombookmarksdombookmarks.pro readXmlFile(m_initFolderPath+"/"+m_xmlFileName); void MainWindow::readXmlFile(QS

QT自带例子:

C:QtQt5.5.1ExamplesQt-5.5widgetsitemviewssimpledommodelsimpledommodel.pro

C:QtQt5.5.1ExamplesQt-5.5xmldombookmarksdombookmarks.pro


readXmlFile(m_initFolderPath+"/"+m_xmlFileName);

void MainWindow::readXmlFile(QString fileName) { QFile file(fileName); if(!file.open(QFile::ReadOnly | QFile::Text)) { qDebug()<<"open file"<<fileName<<"failed,error:"<<file.errorString(); return; } QDomDocument document; QString strError; int errLin = 0,errCol = 0; if( !document.setContent(&file,false,&strError,&errLin,&errCol) ) { qDebug()<<"parse file failed at line"<<errLin<<",column"<<errCol<<","<<strError; return; } if( document.isNull() ) { qDebug()<<"document is null !"; return; } QDomElement root = document.documentElement(); qDebug()<<root.tagName(); QDomElement catalogs = root.firstChildElement(); if( catalogs.isNull() ) { return; } else { //qDebug()<<catalogs.tagName(); } while(!catalogs.isNull()) { foreachElement(catalogs); catalogs = catalogs.nextSiblingElement(); } file.close(); } void MainWindow::foreachElement(QDomElement catalogs) { if(catalogs.tagName()=="") return; //qDebug()<<catalogs.tagName(); if(catalogs.hasAttributes()) { QDomNamedNodeMap map = catalogs.attributes(); if(catalogs.tagName()==NodeSystemButton) { createSystemButton(map); } else if(catalogs.tagName()==NodeSAction) { createSAction(map); } else if(catalogs.tagName()==NodeRibbonPageSystemPopup) { createRibbonPageSystemPopup(map); } else if(catalogs.tagName()==NodeSRAction) { createSRAction(map); } else if(catalogs.tagName()==NodeRibbonQuickAccessBar) { createQuickAccessBar(map); } else if(catalogs.tagName()==NodeExitsAction) { bindingExitsAction(map); } else if(catalogs.tagName()==NodeQuickAction) { createQuickAction(map); } else if(catalogs.tagName()==NodeRibbonPage) { createRibbonPage(map); } else if(catalogs.tagName()==NodeRibbonGroup) { createRibbonGroup(map); } else if(catalogs.tagName()==NodeOptionButtonAction) { } else if(catalogs.tagName()==NodeQMenu) { createPMenu(map); } else if(catalogs.tagName()==NodeQAction) { createPMQAction(map); } else if(catalogs.tagName()==NodePageQAction) { createPageQAction(map); } else if(catalogs.tagName()==NodeRibbonStatusBar) { createRibbonStatusBar(); } else if(catalogs.tagName()==NodeStatusAction) { createStatusAction(map); } } if(catalogs.hasChildNodes()) { for(int i=0;i<catalogs.childNodes().length();++i) { foreachElement(catalogs.childNodes().at(i).toElement()); } } } QString MainWindow::getNodeValue(QDomNamedNodeMap map,QString key) { QString tempValue=map.namedItem(key).nodeValue(); if(key=="Icon") tempValue=m_initFolderPath+"/"+m_imageFolder+"/"+tempValue; return tempValue; }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读