• 大小: 3.76MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-08-11
  • 语言: 其他
  • 标签: QtC++  

资源简介

更多细节,参见博客:http://blog.csdn.net/rl529014/article/details/79090256

资源截图

代码片段和文件信息

#include “ctrlpanel.h“
#include “ui_ctrlpanel.h“
#include 
#include 
#include 
#include 
#include 
#include 
#include ject>
#include 
#include 
#include 

CtrlPanel::CtrlPanel(QWidget *parent) : QWidget(parent) ui(new Ui::CtrlPanel)
{
    ui->setupUi(this);

    mNetManager = new QNetworkAccessManager(this);
    mNetRequest = new QNetworkRequest;

    connect(ui->btnRefresh  SIGNAL(clicked(bool))  SLOT(onBtnRefreshWeather()));
    connect(mNetManagerSIGNAL(finished(QNetworkReply *))thisSLOT(onReplyFinished(QNetworkReply*)));

    QTimer::singleShot(1000 this   SLOT(onSendRequest()));
}

CtrlPanel::~CtrlPanel()
{
    delete ui;
}

void CtrlPanel::onSendRequest()
{
    mNetRequest->setUrl(QUrl(“http://www.weather.com.cn/data/city3jdata/china.html“));
    mNetRequest->setHeader(QNetworkRequest::UserAgentHeader“RT-Thread ART“);
    mNetManager->get(*mNetRequest);
}

void CtrlPanel::onReplyFinished(QNetworkReply *reply)
{
    QByteArray weather = reply->readAll();
    if(!weather.isEmpty())
        analyCitysxml(weather); //解析天气信息的数据
    reply->deleteLater();
}

void CtrlPanel::onBtnRefreshWeather()
{
    if(!ui->comboBox_Citys->currentText().isEmpty())
        emit sngRefreshWeather(ui->comboBox_Citys->currentText());
}

void CtrlPanel::analyCitysxml(QByteArray xml)
{
    if(xml.isEmpty())
        return ;

    QJsonParseError err;
    QStringList citys;
    QJsonDocument jsonDoc = QJsonDocument::fromJson(xml&err);
    QVariantMap variantMap = jsonDoc.object().toVariantMap();
    if(variantMap.count() > 0)
    {
        foreach (auto c variantMap)
        {
            citys.append(c.toString());
        }
        setCitys2UI(citys);
    }
}

void CtrlPanel::setCitys2UI(const QStringList citys)
{
    ui->comboBox_Citys->clear();
    ui->comboBox_Citys->addItems(citys);
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-01-08 22:08  trunk\
     目录           0  2017-12-17 23:07  trunk\.git\
     文件         275  2017-12-17 23:07  trunk\.git\config
     文件          73  2017-10-29 00:46  trunk\.git\description
     文件           0  2017-10-29 00:46  trunk\.git\FETCH_HEAD
     文件          23  2017-10-29 00:46  trunk\.git\HEAD
     目录           0  2017-10-29 00:46  trunk\.git\hooks\
     文件         478  2017-10-29 00:46  trunk\.git\hooks\applypatch-msg.sample
     文件         896  2017-10-29 00:46  trunk\.git\hooks\commit-msg.sample
     文件         189  2017-10-29 00:46  trunk\.git\hooks\post-update.sample
     文件         424  2017-10-29 00:46  trunk\.git\hooks\pre-applypatch.sample
     文件        1642  2017-10-29 00:46  trunk\.git\hooks\pre-commit.sample
     文件        1348  2017-10-29 00:46  trunk\.git\hooks\pre-push.sample
     文件        4951  2017-10-29 00:46  trunk\.git\hooks\pre-rebase.sample
     文件         544  2017-10-29 00:46  trunk\.git\hooks\pre-receive.sample
     文件        1239  2017-10-29 00:46  trunk\.git\hooks\prepare-commit-msg.sample
     文件        3610  2017-10-29 00:46  trunk\.git\hooks\update.sample
     文件         230  2017-11-02 23:29  trunk\.git\index
     目录           0  2017-10-29 00:46  trunk\.git\info\
     文件         240  2017-10-29 00:46  trunk\.git\info\exclude
     目录           0  2017-11-02 23:29  trunk\.git\objects\
     目录           0  2017-11-02 23:29  trunk\.git\objects\0b\
     文件       64350  2017-11-02 23:29  trunk\.git\objects\0b\1bb274eb5f8eaabc3b4cb3254bacd2f08bdcdb
     目录           0  2017-10-29 00:46  trunk\.git\objects\4b\
     文件          15  2017-12-17 23:06  trunk\.git\objects\4b\825dc642cb6eb9a060e54bf8d69288fbee4904
     目录           0  2017-11-02 23:29  trunk\.git\objects\94\
     文件      302095  2017-11-02 23:29  trunk\.git\objects\94\cd3c20bfd78e36fde48ee2cd5b4e2a2a0fe3e5
     目录           0  2017-10-29 00:46  trunk\.git\objects\info\
     目录           0  2017-10-29 00:46  trunk\.git\objects\pack\
     目录           0  2017-10-29 00:46  trunk\.git\refs\
     目录           0  2017-10-29 00:46  trunk\.git\refs\heads\
............此处省略381个文件信息

评论

共有 条评论