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

  • 相关阅读:
    HTML和CSS 基本要点必看
    CSS
    六个选择器
    HTML初级课程 (自学可懂)
    this
    1.作用域链
    js if 语句
    js数据类型
    ifelse语句
    三元运算符
  • 原文地址:https://www.cnblogs.com/zzxap/p/2175730.html
Copyright © 2020-2023  润新知