QT 下载文件解析XML
#include "readxml.h"
#include "ui_readxml.h"
#include <QXmlStreamReader>
#include <QMessageBox>
#include<QFile>
#include <qt4/QtXml/qdom.h>#include <HttpGet.h>#include <QUrl>ReadXml::ReadXml(QWidget *parent) :QDialog(parent),ui(new Ui::ReadXml){ui->setupUi(this);}ReadXml::~ReadXml(){delete ui;}void ReadXml::on_readXml_clicked(){QDomDocument doc("mydocument");QFile file("configfilepath_temp.xml");if (!file.open(QIODevice::ReadOnly))return;if (!doc.setContent(&file)){//file.close();// return;}file.close();QDomElement docElem = doc.documentElement();//QDomNodeList nodeList = docElem.elementsByTagName("Proxy").at(0).toElement().elementsByTagName("ProxyTypes").at(0).toElement().elementsByTagName("Type");QDomNodeList nodeList = docElem.elementsByTagName("Section").at(1).toElement().elementsByTagName("Key");if (nodeList.count() > 0){ HttpGet getter;for(int iDx = 0;iDx < nodeList.count(); iDx++){bool bOk = false;//int iD = nodeList.at(iDx).attributes().namedItem("Enc").nodeValue().toInt(&bOk,10);QString Type(nodeList.at(iDx).attributes().namedItem("Value").nodeValue());ui->comboBox->addItem(Type,iDx);getter.downloadFile(QUrl(Type));QObject::connect(&getter, SIGNAL(finished()), SLOT(quit()));}}}void ReadXml::on_downXml_clicked(){HttpGet getter;getter.downloadFile(QUrl("http://dev.pubds.com/configFile/2/4/configfilepath_temp.xml"));QObject::connect(&getter, SIGNAL(finished()), SLOT(quit()));/*QHttp *http;http=new QHttp();QUrl *url=new QUrl("http://hi.baidu.com/sdink/blog/item/6178ccb77650bcc537d3ca68.html"); // this can downloadQFileInfo fileinfo(url->path());QFile *file = new QFile(fileinfo.fileName());file->open(QIODevice::WriteOnly);http->setHost(url->host(),80);int httpGetId=http->get(url->path(),file);QString errore=http->readAll();ui->textEdit->setText(errore);qDebug() << httpGetId;http->closeConnection();file->close();*/}
浙公网安备 33010602011771号