• 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 download
       
                    QFileInfo 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();*/
    }

  • 相关阅读:
    Gym-102040B Counting Inversion
    hdu 6899 Xor
    CSPS2019游记
    [网络流系列]网络流基础
    [线段树系列]几道不错的线段树题目题解
    浅谈矩阵[简洁易懂]——上篇
    DP动态规划学习笔记——高级篇上
    DP动态规划学习笔记
    [点分治系列] 静态点分
    [数论系列] 素数篇
  • 原文地址:https://www.cnblogs.com/zzxap/p/2175730.html
Copyright © 2020-2023  润新知