参考: 大轮明王讲Qt【QT开发专题-天气预报】
环境
- 目前只兼容
Qt 5.14.2 MinGW 64-bit;Qt Creator 4.11.1
和Qt 5.15.2 MinGW 64-bit;Qt Creator 9.0.1
- 在UI设计器生成的头文件中
ui_weather.h
void retranslateUi(QWidget *Weather)
{
#if QT_VERSION <= QT_VERSION_CHECK(5, 14, 2)
// Qt 5.14.2特定的代码
#else
// Qt 5.15.12特定的代码
#endif
// 通用的代码
}
// 5.14.2的接口与Qt 5.15.12不同,不能使用if else来判断版本号,可以使用编译指令来控制不同版本的代码是否参与编译
- 如果还是不行,就直接删除
ui_weather.h
,再构造就行
weather.pro
QT += core gui
QT += network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
weather.cpp
HEADERS += \
weather.h \
weatherdata.h \
weathertool.h
FORMS += \
weather.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
RESOURCES += \
main.qrc
main.cpp
#include "weather.h"
#include <QApplication>
#include <QtCore>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// 获取Qt的版本号
QString qtVersion = QString::fromLatin1(qVersion());
if (qtVersion.startsWith(QStringLiteral("5.15.2"))) {
qDebug() << "This is Qt 5.15.2";
} else if (qtVersion.startsWith(QStringLiteral("5.14.2"))) {
qDebug() << "This is Qt 5.14.2";
} else {
qDebug() << "Unknown Qt version: " << qtVersion;
}
Weather w;
w.show();
return a.exec();
}
weather.h
#ifndef WEATHER_H
#define WEATHER_H
#include <QWidget>
#include <QContextMenuEvent>
#include <QMenu>
#include <QAction>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include<QLabel>
#include<QPainter>
#include "weatherdata.h"
//不能再次包含头文件,weather.h多次包含,weathertool.h也会多次包含
//#include "weathertool.h"
QT_BEGIN_NAMESPACE
namespace Ui { class Weather; }
QT_END_NAMESPACE
class Weather : public QWidget
{
Q_OBJECT
public:
Weather(QWidget *parent = nullptr);
~Weather();
private:
Ui::Weather *ui;
protected:
void contextMenuEvent(QContextMenuEvent *e);
void mousePressEvent(QMouseEvent *e); // 鼠标点击事件
void mouseMoveEvent(QMouseEvent *e); // 鼠标移动事件
void getWeatherInfo(QString cityName); // 通过城市编码获取天气信息
void parseJson(QByteArray& byteArray); // 分析Json数据
void updateUI(); // 更新UI
// 重写父类的eventFilter方法
bool eventFilter(QObject* watched,QEvent *e);
void paintHighCurve();//绘制高温曲线
void paintLowCurve();//绘制低温曲线
private:
QMenu *mExitMenu;// 右键菜单
QAction *mExitAct;// 退出的行为-右键菜单项
QPoint mOffset;// 窗口移动时,鼠标与窗口左上角的偏移
QNetworkAccessManager *mNetAccessManager;// Http请求
Today mToday;// 今天
Day mDay[6];// 6天数据
QList<QLabel*> mWeekList; // 星期
QList<QLabel*> mDateList; // 日期
QList<QLabel*> mTypeList; // 天气类型
QList<QLabel*> mTypeIconList; // 天气类型图标
QList<QLabel*> mAqiList; // 天气污染指数
QList<QLabel*> mFxList; // 风向
QList<QLabel*> mFlList; // 风力
QMap<QString,QString> mTypeMap;// 天气类型图标路径
private slots:
void onReplied(QNetworkReply *reply);// 处理HTTP服务返回数据
void on_btnSearch_4_clicked();
};
#endif // WEATHER_H
weather.cpp
#include "weather.h"
#include "ui_weather.h"
#include<QDebug>
#include<QMessageBox>
#include <QJsonDocument>
#include<QJsonObject>
#include<QJsonArray>
#define INCREMENT 3 // 温度每升高/降低 1°,y轴坐标的增量
#define POINT_RADIUS 3 // 曲线描点的大小(点的半径)
#define TEXT_OFFSET_X 12 // 文字偏移
#define TEXT_OFFSET_X 12
Weather::Weather(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Weather)
{
ui->setupUi(this);
setWindowFlag(Qt::FramelessWindowHint); // 无边框
setFixedSize(800,450);// 固定窗口大小
{// 右键退出
mExitMenu=new QMenu(this);
mExitAct=new QAction();
mExitAct->setText("退出");
mExitAct->setIcon(QIcon(":/res/close.png"));
mExitMenu->addAction(mExitAct);
connect(mExitAct,&QAction::triggered,this,[=](){
qApp->exit(0);
});
}
//网络对象
mNetAccessManager=new QNetworkAccessManager(this);
connect(mNetAccessManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(onReplied(QNetworkReply *)));
// 默认获取 北京 天气信息
getWeatherInfo("北京");
{// 将控件放到数组里面,方便使用循环进行处理
// 星期
mWeekList<<ui->lblWeek0_4<<ui->lblWeek1_4<<ui->lblWeek2_4<<ui->lblWeek3_4<<ui->lblWeek4_4<<ui->lblWeek5_4;
// 日期
mDateList<<ui->lblDate0_4<<ui->lblDate1_4<<ui->lblDate2_4<<ui->lblDate3_4<<ui->lblDate4_4<<ui->lblDate5_4;
// 天气类型
mTypeList<<ui->lblType0_4<<ui->lblType1_4<<ui->lblType2_4<<ui->lblType3_4<<ui->lblType4_4<<ui->lblType5_4;
// 天气类型图标
mTypeIconList<<ui->lblTypeIcon0_4<<ui->lblTypeIcon1_4<<ui->lblTypeIcon2_4<<ui->lblTypeIcon3_4<<ui->lblTypeIcon4_4<<ui->lblTypeIcon5_4;
// 天气污染指数
mAqiList<<ui->lblQuality0_4<<ui->lblQuality1_4<<ui->lblQuality2_4<<ui->lblQuality3_4<<ui->lblQuality4_4<<ui->lblQuality5_4;
// 风向
mFxList<<ui->lblFx0_4<<ui->lblFx1_4<<ui->lblFx2_4<<ui->lblFx3_4<<ui->lblFx4_4<<ui->lblFx5_4;
// 风力
mFlList<<ui->lblFl0_4<<ui->lblFl1_4<<ui->lblFl2_4<<ui->lblFl3_4<<ui->lblFl4_4<<ui->lblFl5_4;
// 天气类型图标路径
//根据keys,设置icon的路径
mTypeMap.insert("暴雪",":/res/type/BaoXue.png");
mTypeMap.insert("暴雨",":/res/type/BaoYu. png");
mTypeMap.insert("暴雨到大暴雨",":/res/type/BaoYuDaoDaBaoYu.png");
mTypeMap.insert("大暴雨",":/res/type/DaBaoYu.png");
mTypeMap.insert("大暴雨到特大暴雨",":/res/type/DaBaoYuDaoTeDaBaoYu.png");
mTypeMap.insert("大到暴雪",":/res/type/DaDaoBaoXue.png");
mTypeMap.insert("大雪",":/res/type/DaXue.png");
mTypeMap.insert("大雨",":/res/type/DaYu.png");
mTypeMap.insert("冻雨",":/res/type/DongYu.png");
mTypeMap.insert("多云",":/res/type/DuoYun.png");
mTypeMap.insert("浮沉",":/res/type/FuChen.png");
mTypeMap.insert("雷阵雨",":/res/type/LeiZhenYu.png");
mTypeMap.insert("雷阵雨伴有冰雹",":/res/type/LeiZhenYuBanYouBingBao.png");
mTypeMap.insert("霾",":/res/type/Mai.png");
mTypeMap.insert("强沙尘暴",":/res/type/QiangShaChenBao.png");
mTypeMap.insert("晴",":/res/type/Qing.png");
mTypeMap.insert("沙尘暴",":/res/type/ShaChenBao.png");
mTypeMap.insert("特大暴雨",":/res/type/TeDaBaoYu.png");
mTypeMap.insert("undefined",":/res/type/undefined.png");
mTypeMap.insert("雾",":/res/type/Wu.png");
mTypeMap.insert("小到中雪",":/res/type/XiaoDaoZhongXue.png");
mTypeMap.insert("小到中雨",":/res/type/XiaoDaoZhongYu.png");
mTypeMap.insert("小雪",":/res/type/XiaoXue.png");
mTypeMap.insert("小雨",":/res/type/XiaoYu.png");
mTypeMap.insert("雪",":/res/type/Xue.png");
mTypeMap.insert("扬沙",":/res/type/YangSha.png");
mTypeMap.insert("阴",":/res/type/Yin.png");
mTypeMap.insert("雨",":/res/type/Yu.png");
mTypeMap.insert("雨夹雪",":/res/type/YuJiaXue.png");
mTypeMap.insert("阵雪",":/res/type/ZhenXue.png");
mTypeMap.insert("阵雨",":/res/type/ZhenYu.png");
mTypeMap.insert("中到大雪",":/res/type/ZhongDaoDaXue.png");
mTypeMap.insert("中到大雨",":/res/type/ZhongDaoDaYu.png");
mTypeMap.insert("中雪",":/res/type/ZhongXue.png");
mTypeMap.insert("中雨",":/res/type/ZhongYu.png");
}
//给标签安装事件过滤器,捕获所有事件
//参数指定为this,也就是当前窗口对象
ui->lblHighCurve_4->installEventFilter(this);
ui->lblLowCurve_4->installEventFilter(this);
}
Weather::~Weather()
{
delete ui;
}
//重写父类的虚函数
//父类中默认的实现是忽略右键菜单事件
//重写之后,就可以处理右键菜单
void Weather::contextMenuEvent(QContextMenuEvent *e)
{
// 弹出右键菜单
mExitMenu->exec(QCursor::pos());
//调用accept表示,这个事件我已经处理,不需要向上传递了
e->accept();//被用于接受QContextMenuEvent事件并将其标记为已处理,以便不会再次触发相同的事件
}
// 鼠标点击事件
void Weather::mousePressEvent(QMouseEvent *e)
{
mOffset=e->globalPos()-this->pos();
}
// 鼠标移动事件
void Weather::mouseMoveEvent(QMouseEvent *e)
{
this->move(e->globalPos()-mOffset);
}
#include "weathertool.h"
// 在头文件中定义了静态变量,然后在多个源文件中包含了这个头文件,
// 就会出现同一个变量被多次定义的情况,从而导致链接错误,所以放在.cpp中
// 通过城市编码获取天气信息
void Weather::getWeatherInfo(QString cityName)
{
QString cityCode=WeatherTool::getCityCode(cityName);
if(cityCode.isEmpty()){
QMessageBox::warning(this,"天气","请检查输入是否正确!",QMessageBox::Ok);
return;
}
QUrl url("http://t.weather.itboy.net/api/weather/city/"+cityCode);
mNetAccessManager->get(QNetworkRequest(url));
}
// 分析Json数据
void Weather::parseJson(QByteArray &byteArray)
{
QJsonParseError err;
QJsonDocument doc=QJsonDocument::fromJson(byteArray,&err);
if(err.error!=QJsonParseError::NoError)
{
qDebug()<<"parse Json error";
return;
}
QJsonObject rootObj=doc.object();// 根下的对象
qDebug()<<rootObj.value("message").toString();
//1.解析日期和城市
mToday.date = rootObj.value("date").toString();
mToday.city = rootObj.value("cityInfo").toObject().value("city").toString();
//2.解析yesterday
QJsonObject objData = rootObj.value("data").toObject();
QJsonObject objYesterday = objData.value("yesterday").toObject();
mDay[0].date=objYesterday.value("ymd").toString();
mDay[0].week=objYesterday.value("week").toString();
mDay[0].type=objYesterday.value("type").toString();
qDebug()<<"high :"<<objYesterday.value("high").toString();
// "high":"高温 18°","low":"低温 6°"
QString s;
s=objYesterday.value("high").toString().split(" ").at(1);// 18°
s=s.left(s.length()-1);// 18
mDay[0].high=s.toInt();
s=objYesterday.value("low").toString().split(" ").at(1);// 6°
s=s.left(s.length()-1);// 6
mDay[0].low=s.toInt();
mDay[0].fl = objYesterday.value("fl").toString();// 风力
mDay[0].fx = objYesterday.value("fx").toString();// 风向
mDay[0].aqi = objYesterday.value("aqi").toDouble();// 天气污染指数
//3.解析forecast中5天的数据
QJsonArray forecastArr = objData.value("forecast").toArray();
for (int i=0;i<5;i++){
QJsonObject objForecast = forecastArr[i].toObject();
mDay[i+1].date=objForecast.value("ymd").toString();
mDay[i+1].week=objForecast.value("week").toString();
mDay[i+1].type=objForecast.value("type").toString();
QString s;// "high":"高温 18°","low":"低温 6°"
s=objForecast.value("high").toString().split(" ").at(1);// 18°
s=s.left(s.length()-1);// 18
mDay[i+1].high=s.toInt();
s=objForecast.value("low").toString().split(" ").at(1);// 6°
s=s.left(s.length()-1);// 6
mDay[i+1].low=s.toInt();
mDay[i+1].fl = objForecast.value("fl").toString();// 风力
mDay[i+1].fx = objForecast.value("fx").toString();// 风向
mDay[i+1].aqi = objForecast.value("aqi").toDouble();// 天气污染指数
}
//4.解析今天的数据
mToday.ganmao = objData.value("ganmao").toString();
mToday.wendu = objData.value("wendu").toString().toInt();
mToday.shidu = objData.value("shidu").toString();
mToday.pm25 = objData.value("pm25").toInt();
mToday.quality = objData.value("quality").toString();
//5. 在forecast中的第一个数组元素,也就是今天的数据
mToday.type = mDay[1].type;
mToday.fx = mDay[1].fx;
mToday.fl = mDay[1].fl;
mToday.high = mDay[1].high;
mToday.low = mDay[1].low;
//6. 更新UI
updateUI();
//7. 绘制曲线
ui->lblHighCurve_4->update();//触发绘画事件
ui->lblLowCurve_4->update();
}
// 更新UI
void Weather::updateUI()
{
// 日期
ui->lbDate_4->setText(QDateTime::fromString(mToday.date,"yyyyMMdd").toString("yyyy/MM/dd")+" "+mDay[1].week);
ui->lbCity_4->setText(mToday.city);// 城市
//1. 更新今天
ui->lbTemp_4->setText(QString::number(mToday.wendu)+"°");
ui->lbType_4->setText(mToday.type);
ui->lbTypeIcon_4->setPixmap(mTypeMap[mToday.type]);// 天气类型图标
ui->lbLowHigh_4->setText(QString::number(mToday.low)+"~"+QString::number(mToday.high)+"°C");
ui->lbGaoMao_4->setText("感冒指数:"+mToday.ganmao);
ui->lbWindFx_4->setText(mToday.fx);
ui->lbWindFl_4->setText(mToday.fl);
ui->lbPm25_4->setText(QString::number(mToday.pm25));
ui->lbShiDu_4->setText(mToday.shidu);
ui->lblQuality_4->setText(mToday.quality);// 空气质量
//2. 更新6天
for (int i=0;i<6;i++) {
// 日期
mWeekList[i]->setText("周"+mDay[i].week.right(1));// mDay[i].week="星期x"
ui->lblWeek0_4->setText("昨天");
ui->lblWeek1_4->setText("今天");
ui->lblWeek2_4->setText("明天");
// 时间
QStringList ymdList=mDay[i].date.split("-");// mDay[i].date="2023-03-26"
mDateList[i]->setText(ymdList[1]+"/"+ymdList[2]);
// 天气类型
mTypeList[i]->setText(mDay[i].type);
// 天气类型图标
mTypeIconList[i]->setPixmap(mTypeMap[mDay[i].type]);
// 空气质量
if(mDay[i].aqi >= 0 && mDay[i].aqi <= 50){
mAqiList[i]->setText("优");
mAqiList[i]->setStyleSheet("background-color:rgb(121,184,0);");
}else if(mDay[i].aqi > 50 && mDay[i].aqi <= 100){
mAqiList[i]->setText("良");
mAqiList[i]->setStyleSheet("background-color:rgb(255,187,23);");
}else if(mDay[i].aqi > 100 && mDay[i].aqi <= 150){
mAqiList[i]->setText("轻度");
mAqiList[i]->setStyleSheet("background-color:rgb(255,87,97);");
}else if(mDay[i].aqi > 150 && mDay[i].aqi <= 200){
mAqiList[i]->setText("中度");
mAqiList[i]->setStyleSheet("background-color:rgb(235,17,27);");
}else if(mDay[i].aqi > 200 && mDay[i].aqi <= 250){
mAqiList[i]->setText("重度");
mAqiList[i]->setStyleSheet("background-color:rgb(170,0,0);");
}else {
mAqiList[i]->setText("严重");
mAqiList[i]->setStyleSheet("background-color:rgb(110,0,0);");
}
// 风向
mFxList[i]->setText(mDay[i].fx);
mFlList[i]->setText(mDay[i].fl);//风力
}
}
// 重写父类的eventFilter方法
bool Weather::eventFilter(QObject *watched, QEvent *e)
{
if(watched == ui->lblHighCurve_4 && e->type() == QEvent::Paint){
paintHighCurve();
}
if(watched == ui->lblLowCurve_4 && e->type() == QEvent::Paint){
paintLowCurve();
}
// 事件过滤中,只对特殊的进行处理,其他无关的,走原路[父类的eventFilter]
return QWidget::eventFilter(watched,e);
}
//绘制高温曲线
void Weather::paintHighCurve()
{
QPainter painter(ui->lblHighCurve_4);// 画家类
// 抗锯齿
painter.setRenderHint(QPainter::Antialiasing,true);
// 1. 获取x轴坐标
int pointX[6]={0};
for(int i=0;i<6;i++){
pointX[i]=mWeekList[i]->pos().x()+(mWeekList[i]->width()/4);
}
// 2. 获取y轴坐标
int tempSum=0;//总和
int tempAverage=0;//平均
for(int i=0;i<6;i++){
tempSum+=mDay[i].high;
}
tempAverage=tempSum/6; // 最高温的平均值
// 计算y轴坐标
int pointY[6]={0};
int yCenter = ui->lblHighCurve_4->height()/2;
for(int i=0;i<6;i++){
pointY[i]=yCenter - ((mDay[i].high-tempAverage)*INCREMENT);
}
// 3. 开始绘制
// 3.1 初始化画笔相关
QPen pen=painter.pen();
pen.setWidth(1); //设置画笔的宽度
pen.setColor(QColor(255,170,0)); //设置画笔的颜色
painter.setPen(pen);//给画家设置画笔
painter.setBrush(QColor(255,170,0));//设置画刷的颜色-内部填充的颜色
// 3.2 画点、画文字
for(int i=0;i<6;i++){
// 显示点
painter.drawEllipse(QPoint(pointX[i],pointY[i]),POINT_RADIUS,POINT_RADIUS);
// 显示温度
painter.drawText(pointX[i]-TEXT_OFFSET_X,pointY[i]-TEXT_OFFSET_X,
QString::number(mDay[i].high));
}
// 3.3绘制曲线
for(int i=0;i<6-1;i++){
if(i == 0){
pen.setStyle(Qt::DotLine);//虚线
painter.setPen(pen);
}else{
pen.setStyle(Qt::SolidLine);//虚线
painter.setPen(pen);
}
painter.drawLine(pointX[i],pointY[i],pointX[i+1],pointY[i+1]);
}
}
//绘制低温曲线
void Weather::paintLowCurve()
{
QPainter painter(ui->lblLowCurve_4);// 画家类
// 抗锯齿
painter.setRenderHint(QPainter::Antialiasing,true);
// 1. 获取x轴坐标
int pointX[6]={0};
for(int i=0;i<6;i++){
pointX[i]=mWeekList[i]->pos().x()+(mWeekList[i]->width()/4);
}
// 2. 获取y轴坐标
int tempSum=0;//总和
int tempAverage=0;//平均
for(int i=0;i<6;i++){
tempSum+=mDay[i].low;
}
tempAverage=tempSum/6; // 最高温的平均值
// 计算y轴坐标
int pointY[6]={0};
int yCenter = ui->lblLowCurve_4->height()/2;
for(int i=0;i<6;i++){
pointY[i]=yCenter - ((mDay[i].low-tempAverage)*INCREMENT);
}
// 3. 开始绘制
// 3.1 初始化画笔相关
QPen pen=painter.pen();
pen.setWidth(1); //设置画笔的宽度
pen.setColor(QColor(0,255,255)); //设置画笔的颜色
painter.setPen(pen);//给画家设置画笔
painter.setBrush(QColor(0,255,255));//设置画刷的颜色-内部填充的颜色
// 3.2 画点、画文字
for(int i=0;i<6;i++){
// 显示点
painter.drawEllipse(QPoint(pointX[i],pointY[i]),POINT_RADIUS,POINT_RADIUS);
// 显示温度
painter.drawText(pointX[i]-TEXT_OFFSET_X,pointY[i]-TEXT_OFFSET_X,
QString::number(mDay[i].low));
}
// 3.3绘制曲线
for(int i=0;i<6-1;i++){
if(i == 0){
pen.setStyle(Qt::DotLine);//虚线
painter.setPen(pen);
}else{
pen.setStyle(Qt::SolidLine);//虚线
painter.setPen(pen);
}
painter.drawLine(pointX[i],pointY[i],pointX[i+1],pointY[i+1]);
}
}
// 处理HTTP服务返回数据
void Weather::onReplied(QNetworkReply *reply)
{
// 响应的状态码为200,表示请求成功
int statusCode=reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qDebug()<<"statusCode:"<< statusCode;
// 请求方法
qDebug()<<"operation:"<< reply->operation();
qDebug()<<"url:"<< reply->url();
// 响应头
qDebug()<<"raw Header:"<< reply->rawHeaderList();
if(statusCode!=200 || reply->error()!=QNetworkReply::NoError)
{
qDebug()<<"error:"<< reply->errorString();
QMessageBox::warning(this,"天气","请求数据失败",QMessageBox::Ok);
}
else
{
QByteArray byteArray=reply->readAll();
//qDebug()<<"readAll:"<< byteArray.data();
parseJson(byteArray);// 分析Json数据
}
reply->deleteLater();//延时释放,防止堆区的接收数据泄漏
}
// 搜索
void Weather::on_btnSearch_4_clicked()
{
QString cityName=ui->leCity_4->text();
getWeatherInfo(cityName);
}
weatherdata.h 今天、未来6天数据体
#ifndef WEATHERDATA_H
#define WEATHERDATA_H
#include <QString>
class Today{
public:
QString date; // 日期
QString city; //城市
QString ganmao; //感冒
int wendu; // 温度
QString shidu; // 湿度
int pm25; // pm2.5
QString quality; //质量
QString type; // 天气类型
QString fx; //风向
QString fl; //风力
int high; //高温
int low; //低温
// 构造函数,默认值
Today(){
date="2023-03-26"; // 日期
city="北京"; //城市
ganmao="感冒指数"; //感冒
wendu=0; // 温度
shidu="0%"; // 湿度
pm25=0; // pm2.5
quality="无数据"; //质量
type="多云"; // 天气类型
fx="南风"; //风向
fl="2级"; //风力
high=30; //高温
low=18; //低温
}
};
class Day{
public:
QString date; // 日期
QString week; // 星期x
QString type; // 天气类型
int high; //高温
int low; //低温
QString fx; //风向
QString fl; //风力
int aqi; // 天气污染指数
// 构造函数,默认值
Day(){
date="2023-03-26"; // 日期
week="周日"; //星期x
type="多云"; // 天气类型
high=0; //高温
low=0; //低温
fx="南风"; //风向
fl="2级"; //风力
aqi=0; // 天气污染指数
}
};
#endif // WEATHERDATA_H
weathertool.h 获取城市编码工具类
#ifndef WEATHERTOOL_H
#define WEATHERTOOL_H
#include <QMap>
#include <QString>
#include <QFile>
#include <QIODevice>
#include<QJsonArray>
#include<QJsonObject>
#include<QJsonDocument>
#include<QJsonParseError>
class WeatherTool{
private:
static QMap<QString,QString> mCityMap;// Key=城市,value=编码
static void initCityMap(){
// 1.读取文件
QString filePath=":/citycode.json";
QFile file(filePath);
file.open(QIODevice::ReadOnly|QIODevice::Text);
QByteArray json=file.readAll();
file.close();
// 2. 解析,并写入到Map
QJsonParseError err;
QJsonDocument doc=QJsonDocument::fromJson(json,&err);
if(err.error!=QJsonParseError::NoError){
return;
}
if(!doc.isArray()){
return;
}
QJsonArray cities = doc.array();
for(int i=0;i<cities.size();i++){
QString city = cities[i].toObject().value("city_name").toString();
QString code = cities[i].toObject().value("city_code").toString();
if(code.size()>0){
mCityMap.insert(city,code);
}
}
}
public:
static QString getCityCode(QString cityName)
{
if(mCityMap.isEmpty()){
initCityMap();
}
QMap<QString,QString>::iterator it=mCityMap.find(cityName);
// 北京 / 北京市
if(it == mCityMap.end()){
it=mCityMap.find(cityName+"市");
}
if(it != mCityMap.end()){
return it.value();
}
return "";
}
};
// 静态成员变量 需要 在类外进行 初始化
QMap<QString,QString> WeatherTool::mCityMap={};
#endif // WEATHERTOOL_H
ui_weather.h UI设计器生成的头文件
/********************************************************************************
** Form generated from reading UI file 'weather.ui'
**
** Created by: Qt User Interface Compiler version 4.8.7
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_WEATHER_H
#define UI_WEATHER_H
//5.15.2的接口与Qt 5.14.2不同,不能使用if else来判断版本号,可以使用编译指令来控制不同版本的代码是否参与编译
#if QT_VERSION <= QT_VERSION_CHECK(5, 14, 2)
// Qt 5.14.2 MinGW 64-bit;Qt Creator 4.11.1 (Community)
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QGridLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
#else
// 版本:Qt 5.15.2 MinGW 64-bit;Qt Creator 9.0.1 (Community)
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
#endif
QT_BEGIN_NAMESPACE
class Ui_Weather
{
public:
QWidget *widget;
QWidget *widget_24;
QLabel *lbDate_4;
QLineEdit *leCity_4;
QPushButton *btnSearch_4;
QWidget *widget_25;
QVBoxLayout *verticalLayout_22;
QLabel *lbGaoMao_4;
QWidget *widget_26;
QGridLayout *gridLayout_16;
QHBoxLayout *horizontalLayout_20;
QLabel *lblQualityIcon_4;
QVBoxLayout *verticalLayout_23;
QLabel *lblQualityTitle_4;
QLabel *lblQuality_4;
QHBoxLayout *horizontalLayout_21;
QLabel *lbPm25Icon_4;
QVBoxLayout *verticalLayout_24;
QLabel *lbPm25Title_4;
QLabel *lbPm25_4;
QHBoxLayout *horizontalLayout_4;
QLabel *lbWindIcon_4;
QVBoxLayout *verticalLayout_25;
QLabel *lbWindFx_4;
QLabel *lbWindFl_4;
QHBoxLayout *horizontalLayout_22;
QLabel *lbShiDuIcon_4;
QVBoxLayout *verticalLayout_26;
QLabel *lbShiDuTitle_4;
QLabel *lbShiDu_4;
QWidget *widget_27;
QLabel *lbTypeIcon_4;
QWidget *layoutWidget_4;
QGridLayout *gridLayout_17;
QLabel *lbType_4;
QLabel *lbLowHigh_4;
QLabel *lbCity_4;
QLabel *lbTemp_4;
QWidget *widget_28;
QVBoxLayout *verticalLayout_27;
QWidget *widget_29;
QGridLayout *gridLayout_18;
QLabel *lblWeek0_4;
QLabel *lblWeek1_4;
QLabel *lblWeek2_4;
QLabel *lblWeek3_4;
QLabel *lblWeek4_4;
QLabel *lblWeek5_4;
QLabel *lblDate0_4;
QLabel *lblDate1_4;
QLabel *lblDate2_4;
QLabel *lblDate3_4;
QLabel *lblDate4_4;
QLabel *lblDate5_4;
QWidget *widget_30;
QGridLayout *gridLayout_19;
QLabel *lblTypeIcon0_4;
QLabel *lblTypeIcon4_4;
QLabel *lblTypeIcon2_4;
QLabel *lblTypeIcon1_4;
QLabel *lblTypeIcon3_4;
QLabel *lblType5_4;
QLabel *lblType3_4;
QLabel *lblType2_4;
QLabel *lblType0_4;
QLabel *lblType1_4;
QLabel *lblTypeIcon5_4;
QLabel *lblType4_4;
QWidget *widget_31;
QHBoxLayout *horizontalLayout_23;
QLabel *lblQuality0_4;
QLabel *lblQuality1_4;
QLabel *lblQuality2_4;
QLabel *lblQuality3_4;
QLabel *lblQuality4_4;
QLabel *lblQuality5_4;
QWidget *widget_32;
QVBoxLayout *verticalLayout_28;
QLabel *lblHighCurve_4;
QLabel *lblLowCurve_4;
QWidget *widget_33;
QGridLayout *gridLayout_20;
QLabel *lblFx0_4;
QLabel *lblFx1_4;
QLabel *lblFx2_4;
QLabel *lblFx3_4;
QLabel *lblFx4_4;
QLabel *lblFx5_4;
QLabel *lblFl0_4;
QLabel *lblFl1_4;
QLabel *lblFl2_4;
QLabel *lblFl3_4;
QLabel *lblFl4_4;
QLabel *lblFl5_4;
void setupUi(QWidget *Weather)
{
if (Weather->objectName().isEmpty())
Weather->setObjectName(QString::fromUtf8("Weather"));
Weather->resize(800, 474);
widget = new QWidget(Weather);
widget->setObjectName(QString::fromUtf8("widget"));
widget->setGeometry(QRect(0, 0, 800, 450));
widget->setStyleSheet(QString::fromUtf8("QWidget#widget{\n"
" border-image: url(:/res/background.png);\n"
"}\n"
""));
widget_24 = new QWidget(widget);
widget_24->setObjectName(QString::fromUtf8("widget_24"));
widget_24->setGeometry(QRect(0, 0, 811, 51));
lbDate_4 = new QLabel(widget_24);
lbDate_4->setObjectName(QString::fromUtf8("lbDate_4"));
lbDate_4->setGeometry(QRect(380, 5, 411, 41));
QFont font;
font.setFamily(QString::fromUtf8("Arial"));
font.setPointSize(20);
font.setBold(false);
font.setWeight(50);
font.setKerning(true);
lbDate_4->setFont(font);
lbDate_4->setAlignment(Qt::AlignCenter);
lbDate_4->setOpenExternalLinks(false);
leCity_4 = new QLineEdit(widget_24);
leCity_4->setObjectName(QString::fromUtf8("leCity_4"));
leCity_4->setGeometry(QRect(5, 15, 231, 31));
leCity_4->setStyleSheet(QString::fromUtf8("background-color: rgba(255, 255, 255, 255);\n"
"border-radius:10px;\n"
"padding:2px 4px"));
btnSearch_4 = new QPushButton(widget_24);
btnSearch_4->setObjectName(QString::fromUtf8("btnSearch_4"));
btnSearch_4->setGeometry(QRect(238, 15, 31, 31));
btnSearch_4->setStyleSheet(QString::fromUtf8("border-radius:5px;\n"
"background-color: rgb(0, 253, 255);"));
QIcon icon;
icon.addFile(QString::fromUtf8(":/res/search.png"), QSize(), QIcon::Normal, QIcon::Off);
btnSearch_4->setIcon(icon);
widget_25 = new QWidget(widget);
widget_25->setObjectName(QString::fromUtf8("widget_25"));
widget_25->setGeometry(QRect(20, 181, 342, 251));
verticalLayout_22 = new QVBoxLayout(widget_25);
verticalLayout_22->setObjectName(QString::fromUtf8("verticalLayout_22"));
lbGaoMao_4 = new QLabel(widget_25);
lbGaoMao_4->setObjectName(QString::fromUtf8("lbGaoMao_4"));
lbGaoMao_4->setWordWrap(true);
verticalLayout_22->addWidget(lbGaoMao_4);
widget_26 = new QWidget(widget_25);
widget_26->setObjectName(QString::fromUtf8("widget_26"));
widget_26->setStyleSheet(QString::fromUtf8("background-color: rgb(65, 156, 255);\n"
"border-radius: 15px"));
gridLayout_16 = new QGridLayout(widget_26);
gridLayout_16->setObjectName(QString::fromUtf8("gridLayout_16"));
horizontalLayout_20 = new QHBoxLayout();
horizontalLayout_20->setObjectName(QString::fromUtf8("horizontalLayout_20"));
lblQualityIcon_4 = new QLabel(widget_26);
lblQualityIcon_4->setObjectName(QString::fromUtf8("lblQualityIcon_4"));
lblQualityIcon_4->setMinimumSize(QSize(40, 40));
lblQualityIcon_4->setMaximumSize(QSize(40, 40));
QFont font1;
font1.setPointSize(10);
lblQualityIcon_4->setFont(font1);
lblQualityIcon_4->setPixmap(QPixmap(QString::fromUtf8(":/res/aqi.png")));
lblQualityIcon_4->setScaledContents(true);
horizontalLayout_20->addWidget(lblQualityIcon_4);
verticalLayout_23 = new QVBoxLayout();
verticalLayout_23->setObjectName(QString::fromUtf8("verticalLayout_23"));
lblQualityTitle_4 = new QLabel(widget_26);
lblQualityTitle_4->setObjectName(QString::fromUtf8("lblQualityTitle_4"));
lblQualityTitle_4->setFont(font1);
lblQualityTitle_4->setAlignment(Qt::AlignCenter);
verticalLayout_23->addWidget(lblQualityTitle_4);
lblQuality_4 = new QLabel(widget_26);
lblQuality_4->setObjectName(QString::fromUtf8("lblQuality_4"));
lblQuality_4->setFont(font1);
lblQuality_4->setAlignment(Qt::AlignCenter);
verticalLayout_23->addWidget(lblQuality_4);
horizontalLayout_20->addLayout(verticalLayout_23);
gridLayout_16->addLayout(horizontalLayout_20, 1, 1, 1, 1);
horizontalLayout_21 = new QHBoxLayout();
horizontalLayout_21->setObjectName(QString::fromUtf8("horizontalLayout_21"));
lbPm25Icon_4 = new QLabel(widget_26);
lbPm25Icon_4->setObjectName(QString::fromUtf8("lbPm25Icon_4"));
lbPm25Icon_4->setMinimumSize(QSize(40, 40));
lbPm25Icon_4->setMaximumSize(QSize(40, 40));
lbPm25Icon_4->setFont(font1);
lbPm25Icon_4->setPixmap(QPixmap(QString::fromUtf8(":/res/pm25.png")));
lbPm25Icon_4->setScaledContents(true);
horizontalLayout_21->addWidget(lbPm25Icon_4);
verticalLayout_24 = new QVBoxLayout();
verticalLayout_24->setObjectName(QString::fromUtf8("verticalLayout_24"));
lbPm25Title_4 = new QLabel(widget_26);
lbPm25Title_4->setObjectName(QString::fromUtf8("lbPm25Title_4"));
lbPm25Title_4->setFont(font1);
lbPm25Title_4->setAlignment(Qt::AlignCenter);
verticalLayout_24->addWidget(lbPm25Title_4);
lbPm25_4 = new QLabel(widget_26);
lbPm25_4->setObjectName(QString::fromUtf8("lbPm25_4"));
lbPm25_4->setFont(font1);
lbPm25_4->setAlignment(Qt::AlignCenter);
verticalLayout_24->addWidget(lbPm25_4);
horizontalLayout_21->addLayout(verticalLayout_24);
gridLayout_16->addLayout(horizontalLayout_21, 0, 1, 1, 1);
horizontalLayout_4 = new QHBoxLayout();
horizontalLayout_4->setObjectName(QString::fromUtf8("horizontalLayout_4"));
lbWindIcon_4 = new QLabel(widget_26);
lbWindIcon_4->setObjectName(QString::fromUtf8("lbWindIcon_4"));
lbWindIcon_4->setMinimumSize(QSize(40, 40));
lbWindIcon_4->setMaximumSize(QSize(40, 40));
lbWindIcon_4->setFont(font1);
lbWindIcon_4->setPixmap(QPixmap(QString::fromUtf8(":/res/wind.png")));
lbWindIcon_4->setScaledContents(true);
horizontalLayout_4->addWidget(lbWindIcon_4);
verticalLayout_25 = new QVBoxLayout();
verticalLayout_25->setObjectName(QString::fromUtf8("verticalLayout_25"));
lbWindFx_4 = new QLabel(widget_26);
lbWindFx_4->setObjectName(QString::fromUtf8("lbWindFx_4"));
lbWindFx_4->setFont(font1);
lbWindFx_4->setAlignment(Qt::AlignCenter);
verticalLayout_25->addWidget(lbWindFx_4);
lbWindFl_4 = new QLabel(widget_26);
lbWindFl_4->setObjectName(QString::fromUtf8("lbWindFl_4"));
lbWindFl_4->setFont(font1);
lbWindFl_4->setAlignment(Qt::AlignCenter);
verticalLayout_25->addWidget(lbWindFl_4);
horizontalLayout_4->addLayout(verticalLayout_25);
gridLayout_16->addLayout(horizontalLayout_4, 0, 0, 1, 1);
horizontalLayout_22 = new QHBoxLayout();
horizontalLayout_22->setObjectName(QString::fromUtf8("horizontalLayout_22"));
lbShiDuIcon_4 = new QLabel(widget_26);
lbShiDuIcon_4->setObjectName(QString::fromUtf8("lbShiDuIcon_4"));
lbShiDuIcon_4->setMinimumSize(QSize(40, 40));
lbShiDuIcon_4->setMaximumSize(QSize(40, 40));
lbShiDuIcon_4->setFont(font1);
lbShiDuIcon_4->setPixmap(QPixmap(QString::fromUtf8(":/res/humidity.png")));
lbShiDuIcon_4->setScaledContents(true);
horizontalLayout_22->addWidget(lbShiDuIcon_4);
verticalLayout_26 = new QVBoxLayout();
verticalLayout_26->setObjectName(QString::fromUtf8("verticalLayout_26"));
lbShiDuTitle_4 = new QLabel(widget_26);
lbShiDuTitle_4->setObjectName(QString::fromUtf8("lbShiDuTitle_4"));
lbShiDuTitle_4->setFont(font1);
lbShiDuTitle_4->setAlignment(Qt::AlignCenter);
verticalLayout_26->addWidget(lbShiDuTitle_4);
lbShiDu_4 = new QLabel(widget_26);
lbShiDu_4->setObjectName(QString::fromUtf8("lbShiDu_4"));
lbShiDu_4->setFont(font1);
lbShiDu_4->setAlignment(Qt::AlignCenter);
verticalLayout_26->addWidget(lbShiDu_4);
horizontalLayout_22->addLayout(verticalLayout_26);
gridLayout_16->addLayout(horizontalLayout_22, 1, 0, 1, 1);
verticalLayout_22->addWidget(widget_26);
widget_27 = new QWidget(widget);
widget_27->setObjectName(QString::fromUtf8("widget_27"));
widget_27->setGeometry(QRect(20, 60, 320, 120));
lbTypeIcon_4 = new QLabel(widget_27);
lbTypeIcon_4->setObjectName(QString::fromUtf8("lbTypeIcon_4"));
lbTypeIcon_4->setGeometry(QRect(10, 10, 81, 81));
lbTypeIcon_4->setPixmap(QPixmap(QString::fromUtf8(":/res/type/Qing.png")));
lbTypeIcon_4->setScaledContents(true);
lbTypeIcon_4->setAlignment(Qt::AlignCenter);
layoutWidget_4 = new QWidget(widget_27);
layoutWidget_4->setObjectName(QString::fromUtf8("layoutWidget_4"));
layoutWidget_4->setGeometry(QRect(100, 0, 221, 115));
gridLayout_17 = new QGridLayout(layoutWidget_4);
gridLayout_17->setObjectName(QString::fromUtf8("gridLayout_17"));
gridLayout_17->setSizeConstraint(QLayout::SetNoConstraint);
gridLayout_17->setVerticalSpacing(1);
gridLayout_17->setContentsMargins(0, 0, 0, 0);
lbType_4 = new QLabel(layoutWidget_4);
lbType_4->setObjectName(QString::fromUtf8("lbType_4"));
lbType_4->setLayoutDirection(Qt::LeftToRight);
lbType_4->setAlignment(Qt::AlignCenter);
gridLayout_17->addWidget(lbType_4, 1, 0, 1, 1);
lbLowHigh_4 = new QLabel(layoutWidget_4);
lbLowHigh_4->setObjectName(QString::fromUtf8("lbLowHigh_4"));
lbLowHigh_4->setAlignment(Qt::AlignCenter);
gridLayout_17->addWidget(lbLowHigh_4, 1, 1, 1, 2);
lbCity_4 = new QLabel(layoutWidget_4);
lbCity_4->setObjectName(QString::fromUtf8("lbCity_4"));
lbCity_4->setAlignment(Qt::AlignCenter);
gridLayout_17->addWidget(lbCity_4, 0, 2, 1, 1);
lbTemp_4 = new QLabel(layoutWidget_4);
lbTemp_4->setObjectName(QString::fromUtf8("lbTemp_4"));
QFont font2;
font2.setPointSize(32);
lbTemp_4->setFont(font2);
lbTemp_4->setAlignment(Qt::AlignCenter);
gridLayout_17->addWidget(lbTemp_4, 0, 0, 1, 2);
widget_28 = new QWidget(widget);
widget_28->setObjectName(QString::fromUtf8("widget_28"));
widget_28->setGeometry(QRect(360, 20, 441, 431));
verticalLayout_27 = new QVBoxLayout(widget_28);
verticalLayout_27->setSpacing(0);
verticalLayout_27->setObjectName(QString::fromUtf8("verticalLayout_27"));
widget_29 = new QWidget(widget_28);
widget_29->setObjectName(QString::fromUtf8("widget_29"));
widget_29->setStyleSheet(QString::fromUtf8("QLabel {\n"
" background-color: rgba(0, 200, 200, 200);\n"
" border-radius: 4px;\n"
"}"));
gridLayout_18 = new QGridLayout(widget_29);
gridLayout_18->setObjectName(QString::fromUtf8("gridLayout_18"));
gridLayout_18->setHorizontalSpacing(6);
gridLayout_18->setVerticalSpacing(0);
lblWeek0_4 = new QLabel(widget_29);
lblWeek0_4->setObjectName(QString::fromUtf8("lblWeek0_4"));
lblWeek0_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblWeek0_4->setAlignment(Qt::AlignCenter);
gridLayout_18->addWidget(lblWeek0_4, 0, 0, 1, 1);
lblWeek1_4 = new QLabel(widget_29);
lblWeek1_4->setObjectName(QString::fromUtf8("lblWeek1_4"));
lblWeek1_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblWeek1_4->setAlignment(Qt::AlignCenter);
gridLayout_18->addWidget(lblWeek1_4, 0, 1, 1, 1);
lblWeek2_4 = new QLabel(widget_29);
lblWeek2_4->setObjectName(QString::fromUtf8("lblWeek2_4"));
lblWeek2_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblWeek2_4->setAlignment(Qt::AlignCenter);
gridLayout_18->addWidget(lblWeek2_4, 0, 2, 1, 1);
lblWeek3_4 = new QLabel(widget_29);
lblWeek3_4->setObjectName(QString::fromUtf8("lblWeek3_4"));
lblWeek3_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblWeek3_4->setAlignment(Qt::AlignCenter);
gridLayout_18->addWidget(lblWeek3_4, 0, 3, 1, 1);
lblWeek4_4 = new QLabel(widget_29);
lblWeek4_4->setObjectName(QString::fromUtf8("lblWeek4_4"));
lblWeek4_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblWeek4_4->setAlignment(Qt::AlignCenter);
gridLayout_18->addWidget(lblWeek4_4, 0, 4, 1, 1);
lblWeek5_4 = new QLabel(widget_29);
lblWeek5_4->setObjectName(QString::fromUtf8("lblWeek5_4"));
lblWeek5_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblWeek5_4->setAlignment(Qt::AlignCenter);
gridLayout_18->addWidget(lblWeek5_4, 0, 5, 1, 1);
lblDate0_4 = new QLabel(widget_29);
lblDate0_4->setObjectName(QString::fromUtf8("lblDate0_4"));
lblDate0_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;\n"
"color: rgb(240, 240, 240);"));
lblDate0_4->setAlignment(Qt::AlignCenter);
gridLayout_18->addWidget(lblDate0_4, 1, 0, 1, 1);
lblDate1_4 = new QLabel(widget_29);
lblDate1_4->setObjectName(QString::fromUtf8("lblDate1_4"));
lblDate1_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;\n"
"color: rgb(240, 240, 240);"));
lblDate1_4->setAlignment(Qt::AlignCenter);
gridLayout_18->addWidget(lblDate1_4, 1, 1, 1, 1);
lblDate2_4 = new QLabel(widget_29);
lblDate2_4->setObjectName(QString::fromUtf8("lblDate2_4"));
lblDate2_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;\n"
"color: rgb(240, 240, 240);"));
lblDate2_4->setAlignment(Qt::AlignCenter);
gridLayout_18->addWidget(lblDate2_4, 1, 2, 1, 1);
lblDate3_4 = new QLabel(widget_29);
lblDate3_4->setObjectName(QString::fromUtf8("lblDate3_4"));
lblDate3_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;\n"
"color: rgb(240, 240, 240);"));
lblDate3_4->setAlignment(Qt::AlignCenter);
gridLayout_18->addWidget(lblDate3_4, 1, 3, 1, 1);
lblDate4_4 = new QLabel(widget_29);
lblDate4_4->setObjectName(QString::fromUtf8("lblDate4_4"));
lblDate4_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;\n"
"color: rgb(240, 240, 240);"));
lblDate4_4->setAlignment(Qt::AlignCenter);
gridLayout_18->addWidget(lblDate4_4, 1, 4, 1, 1);
lblDate5_4 = new QLabel(widget_29);
lblDate5_4->setObjectName(QString::fromUtf8("lblDate5_4"));
lblDate5_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;\n"
"color: rgb(240, 240, 240);"));
lblDate5_4->setAlignment(Qt::AlignCenter);
gridLayout_18->addWidget(lblDate5_4, 1, 5, 1, 1);
verticalLayout_27->addWidget(widget_29);
widget_30 = new QWidget(widget_28);
widget_30->setObjectName(QString::fromUtf8("widget_30"));
widget_30->setStyleSheet(QString::fromUtf8("QLabel {\n"
" background-color: rgba(60, 60, 60, 100);\n"
" border-radius: 4px;\n"
"}"));
gridLayout_19 = new QGridLayout(widget_30);
gridLayout_19->setObjectName(QString::fromUtf8("gridLayout_19"));
gridLayout_19->setVerticalSpacing(0);
gridLayout_19->setContentsMargins(-1, 5, -1, 5);
lblTypeIcon0_4 = new QLabel(widget_30);
lblTypeIcon0_4->setObjectName(QString::fromUtf8("lblTypeIcon0_4"));
lblTypeIcon0_4->setMinimumSize(QSize(0, 0));
lblTypeIcon0_4->setMaximumSize(QSize(1000, 1000));
lblTypeIcon0_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblTypeIcon0_4->setPixmap(QPixmap(QString::fromUtf8(":/res/type/Qing.png")));
lblTypeIcon0_4->setAlignment(Qt::AlignCenter);
gridLayout_19->addWidget(lblTypeIcon0_4, 0, 0, 1, 1);
lblTypeIcon4_4 = new QLabel(widget_30);
lblTypeIcon4_4->setObjectName(QString::fromUtf8("lblTypeIcon4_4"));
lblTypeIcon4_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblTypeIcon4_4->setPixmap(QPixmap(QString::fromUtf8(":/res/type/ZhongYu.png")));
lblTypeIcon4_4->setAlignment(Qt::AlignCenter);
gridLayout_19->addWidget(lblTypeIcon4_4, 0, 4, 1, 1);
lblTypeIcon2_4 = new QLabel(widget_30);
lblTypeIcon2_4->setObjectName(QString::fromUtf8("lblTypeIcon2_4"));
lblTypeIcon2_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblTypeIcon2_4->setPixmap(QPixmap(QString::fromUtf8(":/res/type/DuoYun.png")));
lblTypeIcon2_4->setAlignment(Qt::AlignCenter);
gridLayout_19->addWidget(lblTypeIcon2_4, 0, 2, 1, 1);
lblTypeIcon1_4 = new QLabel(widget_30);
lblTypeIcon1_4->setObjectName(QString::fromUtf8("lblTypeIcon1_4"));
lblTypeIcon1_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblTypeIcon1_4->setPixmap(QPixmap(QString::fromUtf8(":/res/type/XiaoYu.png")));
lblTypeIcon1_4->setAlignment(Qt::AlignCenter);
gridLayout_19->addWidget(lblTypeIcon1_4, 0, 1, 1, 1);
lblTypeIcon3_4 = new QLabel(widget_30);
lblTypeIcon3_4->setObjectName(QString::fromUtf8("lblTypeIcon3_4"));
lblTypeIcon3_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblTypeIcon3_4->setPixmap(QPixmap(QString::fromUtf8(":/res/type/DuoYun.png")));
lblTypeIcon3_4->setAlignment(Qt::AlignCenter);
gridLayout_19->addWidget(lblTypeIcon3_4, 0, 3, 1, 1);
lblType5_4 = new QLabel(widget_30);
lblType5_4->setObjectName(QString::fromUtf8("lblType5_4"));
lblType5_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;"));
lblType5_4->setAlignment(Qt::AlignCenter);
gridLayout_19->addWidget(lblType5_4, 1, 5, 1, 1);
lblType3_4 = new QLabel(widget_30);
lblType3_4->setObjectName(QString::fromUtf8("lblType3_4"));
lblType3_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;"));
lblType3_4->setAlignment(Qt::AlignCenter);
gridLayout_19->addWidget(lblType3_4, 1, 3, 1, 1);
lblType2_4 = new QLabel(widget_30);
lblType2_4->setObjectName(QString::fromUtf8("lblType2_4"));
lblType2_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;"));
lblType2_4->setAlignment(Qt::AlignCenter);
gridLayout_19->addWidget(lblType2_4, 1, 2, 1, 1);
lblType0_4 = new QLabel(widget_30);
lblType0_4->setObjectName(QString::fromUtf8("lblType0_4"));
lblType0_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;"));
lblType0_4->setAlignment(Qt::AlignCenter);
gridLayout_19->addWidget(lblType0_4, 1, 0, 1, 1);
lblType1_4 = new QLabel(widget_30);
lblType1_4->setObjectName(QString::fromUtf8("lblType1_4"));
lblType1_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;"));
lblType1_4->setAlignment(Qt::AlignCenter);
gridLayout_19->addWidget(lblType1_4, 1, 1, 1, 1);
lblTypeIcon5_4 = new QLabel(widget_30);
lblTypeIcon5_4->setObjectName(QString::fromUtf8("lblTypeIcon5_4"));
lblTypeIcon5_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblTypeIcon5_4->setPixmap(QPixmap(QString::fromUtf8(":/res/type/BaoYu.png")));
lblTypeIcon5_4->setAlignment(Qt::AlignCenter);
gridLayout_19->addWidget(lblTypeIcon5_4, 0, 5, 1, 1);
lblType4_4 = new QLabel(widget_30);
lblType4_4->setObjectName(QString::fromUtf8("lblType4_4"));
lblType4_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;"));
lblType4_4->setAlignment(Qt::AlignCenter);
gridLayout_19->addWidget(lblType4_4, 1, 4, 1, 1);
verticalLayout_27->addWidget(widget_30);
widget_31 = new QWidget(widget_28);
widget_31->setObjectName(QString::fromUtf8("widget_31"));
widget_31->setStyleSheet(QString::fromUtf8("border-radius: 4px"));
horizontalLayout_23 = new QHBoxLayout(widget_31);
horizontalLayout_23->setObjectName(QString::fromUtf8("horizontalLayout_23"));
horizontalLayout_23->setContentsMargins(-1, 5, -1, 5);
lblQuality0_4 = new QLabel(widget_31);
lblQuality0_4->setObjectName(QString::fromUtf8("lblQuality0_4"));
lblQuality0_4->setStyleSheet(QString::fromUtf8("background-color: rgb(121, 184, 0);\n"
"padding:8px;"));
lblQuality0_4->setAlignment(Qt::AlignCenter);
horizontalLayout_23->addWidget(lblQuality0_4);
lblQuality1_4 = new QLabel(widget_31);
lblQuality1_4->setObjectName(QString::fromUtf8("lblQuality1_4"));
lblQuality1_4->setStyleSheet(QString::fromUtf8("background-color: rgb(255, 187, 23);"));
lblQuality1_4->setAlignment(Qt::AlignCenter);
horizontalLayout_23->addWidget(lblQuality1_4);
lblQuality2_4 = new QLabel(widget_31);
lblQuality2_4->setObjectName(QString::fromUtf8("lblQuality2_4"));
lblQuality2_4->setStyleSheet(QString::fromUtf8("background-color: rgb(255, 87, 97);"));
lblQuality2_4->setAlignment(Qt::AlignCenter);
horizontalLayout_23->addWidget(lblQuality2_4);
lblQuality3_4 = new QLabel(widget_31);
lblQuality3_4->setObjectName(QString::fromUtf8("lblQuality3_4"));
lblQuality3_4->setStyleSheet(QString::fromUtf8("background-color: rgb(235, 17, 27);"));
lblQuality3_4->setAlignment(Qt::AlignCenter);
horizontalLayout_23->addWidget(lblQuality3_4);
lblQuality4_4 = new QLabel(widget_31);
lblQuality4_4->setObjectName(QString::fromUtf8("lblQuality4_4"));
lblQuality4_4->setStyleSheet(QString::fromUtf8("background-color: rgb(170, 0, 0);"));
lblQuality4_4->setAlignment(Qt::AlignCenter);
horizontalLayout_23->addWidget(lblQuality4_4);
lblQuality5_4 = new QLabel(widget_31);
lblQuality5_4->setObjectName(QString::fromUtf8("lblQuality5_4"));
lblQuality5_4->setStyleSheet(QString::fromUtf8("background-color: rgb(110, 0, 0);"));
lblQuality5_4->setAlignment(Qt::AlignCenter);
horizontalLayout_23->addWidget(lblQuality5_4);
verticalLayout_27->addWidget(widget_31);
widget_32 = new QWidget(widget_28);
widget_32->setObjectName(QString::fromUtf8("widget_32"));
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(widget_32->sizePolicy().hasHeightForWidth());
widget_32->setSizePolicy(sizePolicy);
verticalLayout_28 = new QVBoxLayout(widget_32);
verticalLayout_28->setSpacing(1);
verticalLayout_28->setObjectName(QString::fromUtf8("verticalLayout_28"));
verticalLayout_28->setSizeConstraint(QLayout::SetDefaultConstraint);
verticalLayout_28->setContentsMargins(-1, 5, -1, 5);
lblHighCurve_4 = new QLabel(widget_32);
lblHighCurve_4->setObjectName(QString::fromUtf8("lblHighCurve_4"));
sizePolicy.setHeightForWidth(lblHighCurve_4->sizePolicy().hasHeightForWidth());
lblHighCurve_4->setSizePolicy(sizePolicy);
lblHighCurve_4->setMinimumSize(QSize(0, 0));
lblHighCurve_4->setMaximumSize(QSize(10000, 10000));
lblHighCurve_4->setStyleSheet(QString::fromUtf8("background-color: rgba(60, 60, 60,60);"));
lblHighCurve_4->setAlignment(Qt::AlignCenter);
verticalLayout_28->addWidget(lblHighCurve_4);
lblLowCurve_4 = new QLabel(widget_32);
lblLowCurve_4->setObjectName(QString::fromUtf8("lblLowCurve_4"));
sizePolicy.setHeightForWidth(lblLowCurve_4->sizePolicy().hasHeightForWidth());
lblLowCurve_4->setSizePolicy(sizePolicy);
lblLowCurve_4->setMinimumSize(QSize(0, 0));
lblLowCurve_4->setMaximumSize(QSize(10000, 10000));
lblLowCurve_4->setStyleSheet(QString::fromUtf8("background-color: rgba(60, 60, 60,60);"));
lblLowCurve_4->setAlignment(Qt::AlignCenter);
verticalLayout_28->addWidget(lblLowCurve_4);
verticalLayout_27->addWidget(widget_32);
widget_33 = new QWidget(widget_28);
widget_33->setObjectName(QString::fromUtf8("widget_33"));
widget_33->setStyleSheet(QString::fromUtf8("QLabel {\n"
" background-color: rgba(60, 60, 60, 100);\n"
" border-radius: 4px;\n"
"}"));
gridLayout_20 = new QGridLayout(widget_33);
gridLayout_20->setObjectName(QString::fromUtf8("gridLayout_20"));
gridLayout_20->setVerticalSpacing(0);
lblFx0_4 = new QLabel(widget_33);
lblFx0_4->setObjectName(QString::fromUtf8("lblFx0_4"));
lblFx0_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblFx0_4->setAlignment(Qt::AlignCenter);
gridLayout_20->addWidget(lblFx0_4, 0, 0, 1, 1);
lblFx1_4 = new QLabel(widget_33);
lblFx1_4->setObjectName(QString::fromUtf8("lblFx1_4"));
lblFx1_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblFx1_4->setAlignment(Qt::AlignCenter);
gridLayout_20->addWidget(lblFx1_4, 0, 1, 1, 1);
lblFx2_4 = new QLabel(widget_33);
lblFx2_4->setObjectName(QString::fromUtf8("lblFx2_4"));
lblFx2_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblFx2_4->setAlignment(Qt::AlignCenter);
gridLayout_20->addWidget(lblFx2_4, 0, 2, 1, 1);
lblFx3_4 = new QLabel(widget_33);
lblFx3_4->setObjectName(QString::fromUtf8("lblFx3_4"));
lblFx3_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblFx3_4->setAlignment(Qt::AlignCenter);
gridLayout_20->addWidget(lblFx3_4, 0, 3, 1, 1);
lblFx4_4 = new QLabel(widget_33);
lblFx4_4->setObjectName(QString::fromUtf8("lblFx4_4"));
lblFx4_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblFx4_4->setAlignment(Qt::AlignCenter);
gridLayout_20->addWidget(lblFx4_4, 0, 4, 1, 1);
lblFx5_4 = new QLabel(widget_33);
lblFx5_4->setObjectName(QString::fromUtf8("lblFx5_4"));
lblFx5_4->setStyleSheet(QString::fromUtf8("border-bottom-left-radius: 0px;\n"
"border-bottom-right-radius: 0px;"));
lblFx5_4->setAlignment(Qt::AlignCenter);
gridLayout_20->addWidget(lblFx5_4, 0, 5, 1, 1);
lblFl0_4 = new QLabel(widget_33);
lblFl0_4->setObjectName(QString::fromUtf8("lblFl0_4"));
lblFl0_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;\n"
"color: rgb(240, 240, 240);"));
lblFl0_4->setAlignment(Qt::AlignCenter);
gridLayout_20->addWidget(lblFl0_4, 1, 0, 1, 1);
lblFl1_4 = new QLabel(widget_33);
lblFl1_4->setObjectName(QString::fromUtf8("lblFl1_4"));
lblFl1_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;\n"
"color: rgb(240, 240, 240);"));
lblFl1_4->setAlignment(Qt::AlignCenter);
gridLayout_20->addWidget(lblFl1_4, 1, 1, 1, 1);
lblFl2_4 = new QLabel(widget_33);
lblFl2_4->setObjectName(QString::fromUtf8("lblFl2_4"));
lblFl2_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;\n"
"color: rgb(240, 240, 240);"));
lblFl2_4->setAlignment(Qt::AlignCenter);
gridLayout_20->addWidget(lblFl2_4, 1, 2, 1, 1);
lblFl3_4 = new QLabel(widget_33);
lblFl3_4->setObjectName(QString::fromUtf8("lblFl3_4"));
lblFl3_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;\n"
"color: rgb(240, 240, 240);"));
lblFl3_4->setAlignment(Qt::AlignCenter);
gridLayout_20->addWidget(lblFl3_4, 1, 3, 1, 1);
lblFl4_4 = new QLabel(widget_33);
lblFl4_4->setObjectName(QString::fromUtf8("lblFl4_4"));
lblFl4_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;\n"
"color: rgb(240, 240, 240);"));
lblFl4_4->setAlignment(Qt::AlignCenter);
gridLayout_20->addWidget(lblFl4_4, 1, 4, 1, 1);
lblFl5_4 = new QLabel(widget_33);
lblFl5_4->setObjectName(QString::fromUtf8("lblFl5_4"));
lblFl5_4->setStyleSheet(QString::fromUtf8("border-top-left-radius: 0px;\n"
"border-top-right-radius: 0px;\n"
"color: rgb(240, 240, 240);"));
lblFl5_4->setAlignment(Qt::AlignCenter);
gridLayout_20->addWidget(lblFl5_4, 1, 5, 1, 1);
verticalLayout_27->addWidget(widget_33);
retranslateUi(Weather);
QMetaObject::connectSlotsByName(Weather);
} // setupUi
void retranslateUi(QWidget *Weather)
{
//5.15.2的接口与Qt 5.14.2不同,不能使用if else来判断版本号,可以使用编译指令来控制不同版本的代码是否参与编译
#if QT_VERSION <= QT_VERSION_CHECK(5, 14, 2)
// Qt 5.14.2 MinGW 64-bit;Qt Creator 4.11.1 (Community)
Weather->setWindowTitle(QApplication::translate("Weather", "Weather", 0, QApplication::UnicodeUTF8));
lbDate_4->setText(QApplication::translate("Weather", "2022/11/26 \346\230\237\346\234\237\345\205\255", 0, QApplication::UnicodeUTF8));
leCity_4->setPlaceholderText(QApplication::translate("Weather", "\350\257\267\350\276\223\345\205\245\350\246\201\346\237\245\350\257\242\347\232\204\345\237\216\345\270\202", 0, QApplication::UnicodeUTF8));
btnSearch_4->setText(QString());
lbGaoMao_4->setText(QApplication::translate("Weather", "\346\204\237\345\206\222\346\214\207\346\225\260\357\274\232\345\204\277\347\253\245\343\200\201\350\200\201\345\271\264\344\272\272\345\217\212\345\277\203\350\204\217\343\200\201\345\221\274\345\220\270\347\263\273\347\273\237\347\226\276\347\227\205\346\202\243\350\200\205\344\272\272\347\276\244\345\272\224\345\207\217\345\260\221\351\225\277\346\227\266\351\227\264\346\210\226\351\253\230\345\274\272\345\272\246\346\210\267\345\244\226\351\224\273\347\202\274", 0, QApplication::UnicodeUTF8));
lblQualityIcon_4->setText(QString());
lblQualityTitle_4->setText(QApplication::translate("Weather", "\347\251\272\346\260\224\350\264\250\351\207\217", 0, QApplication::UnicodeUTF8));
lblQuality_4->setText(QApplication::translate("Weather", "3\347\272\247", 0, QApplication::UnicodeUTF8));
lbPm25Icon_4->setText(QString());
lbPm25Title_4->setText(QApplication::translate("Weather", "PM2.5", 0, QApplication::UnicodeUTF8));
lbPm25_4->setText(QApplication::translate("Weather", "10", 0, QApplication::UnicodeUTF8));
lbWindIcon_4->setText(QString());
lbWindFx_4->setText(QApplication::translate("Weather", "\350\245\277\345\214\227\351\243\216", 0, QApplication::UnicodeUTF8));
lbWindFl_4->setText(QApplication::translate("Weather", "3\347\272\247", 0, QApplication::UnicodeUTF8));
lbShiDuIcon_4->setText(QString());
lbShiDuTitle_4->setText(QApplication::translate("Weather", "\346\271\277\345\272\246", 0, QApplication::UnicodeUTF8));
lbShiDu_4->setText(QApplication::translate("Weather", "3\347\272\247", 0, QApplication::UnicodeUTF8));
lbTypeIcon_4->setText(QString());
lbType_4->setText(QApplication::translate("Weather", "\346\231\264\345\244\251", 0, QApplication::UnicodeUTF8));
lbLowHigh_4->setText(QApplication::translate("Weather", "19\342\204\203~32\342\204\203", 0, QApplication::UnicodeUTF8));
lbCity_4->setText(QApplication::translate("Weather", "\345\214\227\344\272\254", 0, QApplication::UnicodeUTF8));
lbTemp_4->setText(QApplication::translate("Weather", "32\302\260", 0, QApplication::UnicodeUTF8));
lblWeek0_4->setText(QApplication::translate("Weather", "\346\230\250\345\244\251", 0, QApplication::UnicodeUTF8));
lblWeek1_4->setText(QApplication::translate("Weather", "\344\273\212\345\244\251", 0, QApplication::UnicodeUTF8));
lblWeek2_4->setText(QApplication::translate("Weather", "\346\230\216\345\244\251", 0, QApplication::UnicodeUTF8));
lblWeek3_4->setText(QApplication::translate("Weather", "\345\221\250\345\233\233", 0, QApplication::UnicodeUTF8));
lblWeek4_4->setText(QApplication::translate("Weather", "\345\221\250\344\272\224", 0, QApplication::UnicodeUTF8));
lblWeek5_4->setText(QApplication::translate("Weather", "\345\221\250\345\205\255", 0, QApplication::UnicodeUTF8));
lblDate0_4->setText(QApplication::translate("Weather", "01/01", 0, QApplication::UnicodeUTF8));
lblDate1_4->setText(QApplication::translate("Weather", "01/02", 0, QApplication::UnicodeUTF8));
lblDate2_4->setText(QApplication::translate("Weather", "01/03", 0, QApplication::UnicodeUTF8));
lblDate3_4->setText(QApplication::translate("Weather", "01/04", 0, QApplication::UnicodeUTF8));
lblDate4_4->setText(QApplication::translate("Weather", "01/05", 0, QApplication::UnicodeUTF8));
lblDate5_4->setText(QApplication::translate("Weather", "01/06", 0, QApplication::UnicodeUTF8));
lblTypeIcon0_4->setText(QString());
lblTypeIcon4_4->setText(QString());
lblTypeIcon2_4->setText(QString());
lblTypeIcon1_4->setText(QString());
lblTypeIcon3_4->setText(QString());
lblType5_4->setText(QApplication::translate("Weather", "\346\232\264\351\233\250", 0, QApplication::UnicodeUTF8));
lblType3_4->setText(QApplication::translate("Weather", "\345\244\232\344\272\221", 0, QApplication::UnicodeUTF8));
lblType2_4->setText(QApplication::translate("Weather", "\345\244\232\344\272\221", 0, QApplication::UnicodeUTF8));
lblType0_4->setText(QApplication::translate("Weather", "\346\231\264", 0, QApplication::UnicodeUTF8));
lblType1_4->setText(QApplication::translate("Weather", "\345\260\217\351\233\250", 0, QApplication::UnicodeUTF8));
lblTypeIcon5_4->setText(QString());
lblType4_4->setText(QApplication::translate("Weather", "\344\270\255\351\233\250", 0, QApplication::UnicodeUTF8));
lblQuality0_4->setText(QApplication::translate("Weather", "\344\274\230", 0, QApplication::UnicodeUTF8));
lblQuality1_4->setText(QApplication::translate("Weather", "\350\211\257", 0, QApplication::UnicodeUTF8));
lblQuality2_4->setText(QApplication::translate("Weather", "\350\275\273\345\272\246", 0, QApplication::UnicodeUTF8));
lblQuality3_4->setText(QApplication::translate("Weather", "\344\270\255\345\272\246", 0, QApplication::UnicodeUTF8));
lblQuality4_4->setText(QApplication::translate("Weather", "\351\207\215\345\272\246", 0, QApplication::UnicodeUTF8));
lblQuality5_4->setText(QApplication::translate("Weather", "\344\270\245\351\207\215", 0, QApplication::UnicodeUTF8));
lblHighCurve_4->setText(QString());
lblLowCurve_4->setText(QString());
lblFx0_4->setText(QApplication::translate("Weather", "\344\270\234\351\243\216", 0, QApplication::UnicodeUTF8));
lblFx1_4->setText(QApplication::translate("Weather", "\344\270\234\345\214\227\351\243\216", 0, QApplication::UnicodeUTF8));
lblFx2_4->setText(QApplication::translate("Weather", "\350\245\277\345\214\227\351\243\216", 0, QApplication::UnicodeUTF8));
lblFx3_4->setText(QApplication::translate("Weather", "\350\245\277\345\214\227\351\243\216", 0, QApplication::UnicodeUTF8));
lblFx4_4->setText(QApplication::translate("Weather", "\344\270\234\345\215\227\351\243\216", 0, QApplication::UnicodeUTF8));
lblFx5_4->setText(QApplication::translate("Weather", "\350\245\277\351\243\216", 0, QApplication::UnicodeUTF8));
lblFl0_4->setText(QApplication::translate("Weather", "2\347\272\247", 0, QApplication::UnicodeUTF8));
lblFl1_4->setText(QApplication::translate("Weather", "3\347\272\247", 0, QApplication::UnicodeUTF8));
lblFl2_4->setText(QApplication::translate("Weather", "2\347\272\247", 0, QApplication::UnicodeUTF8));
lblFl3_4->setText(QApplication::translate("Weather", "1\347\272\247", 0, QApplication::UnicodeUTF8));
lblFl4_4->setText(QApplication::translate("Weather", "2\347\272\247", 0, QApplication::UnicodeUTF8));
lblFl5_4->setText(QApplication::translate("Weather", "2\347\272\247", 0, QApplication::UnicodeUTF8));
#else
// 版本:Qt 5.15.2 MinGW 64-bit;Qt Creator 9.0.1 (Community)
Weather->setWindowTitle(QApplication::translate("Weather", "Weather",nullptr));
lbDate_4->setText(QApplication::translate("Weather", "2022/11/26 \346\230\237\346\234\237\345\205\255",nullptr));
leCity_4->setPlaceholderText(QApplication::translate("Weather", "\350\257\267\350\276\223\345\205\245\350\246\201\346\237\245\350\257\242\347\232\204\345\237\216\345\270\202",nullptr));
btnSearch_4->setText(QString());
lbGaoMao_4->setText(QApplication::translate("Weather", "\346\204\237\345\206\222\346\214\207\346\225\260\357\274\232\345\204\277\347\253\245\343\200\201\350\200\201\345\271\264\344\272\272\345\217\212\345\277\203\350\204\217\343\200\201\345\221\274\345\220\270\347\263\273\347\273\237\347\226\276\347\227\205\346\202\243\350\200\205\344\272\272\347\276\244\345\272\224\345\207\217\345\260\221\351\225\277\346\227\266\351\227\264\346\210\226\351\253\230\345\274\272\345\272\246\346\210\267\345\244\226\351\224\273\347\202\274",nullptr));
lblQualityIcon_4->setText(QString());
lblQualityTitle_4->setText(QApplication::translate("Weather", "\347\251\272\346\260\224\350\264\250\351\207\217",nullptr));
lblQuality_4->setText(QApplication::translate("Weather", "3\347\272\247",nullptr));
lbPm25Icon_4->setText(QString());
lbPm25Title_4->setText(QApplication::translate("Weather", "PM2.5",nullptr));
lbPm25_4->setText(QApplication::translate("Weather", "10",nullptr));
lbWindIcon_4->setText(QString());
lbWindFx_4->setText(QApplication::translate("Weather", "\350\245\277\345\214\227\351\243\216",nullptr));
lbWindFl_4->setText(QApplication::translate("Weather", "3\347\272\247",nullptr));
lbShiDuIcon_4->setText(QString());
lbShiDuTitle_4->setText(QApplication::translate("Weather", "\346\271\277\345\272\246",nullptr));
lbShiDu_4->setText(QApplication::translate("Weather", "3\347\272\247",nullptr));
lbTypeIcon_4->setText(QString());
lbType_4->setText(QApplication::translate("Weather", "\346\231\264\345\244\251",nullptr));
lbLowHigh_4->setText(QApplication::translate("Weather", "19\342\204\203~32\342\204\203",nullptr));
lbCity_4->setText(QApplication::translate("Weather", "\345\214\227\344\272\254",nullptr));
lbTemp_4->setText(QApplication::translate("Weather", "32\302\260",nullptr));
lblWeek0_4->setText(QApplication::translate("Weather", "\346\230\250\345\244\251",nullptr));
lblWeek1_4->setText(QApplication::translate("Weather", "\344\273\212\345\244\251",nullptr));
lblWeek2_4->setText(QApplication::translate("Weather", "\346\230\216\345\244\251",nullptr));
lblWeek3_4->setText(QApplication::translate("Weather", "\345\221\250\345\233\233",nullptr));
lblWeek4_4->setText(QApplication::translate("Weather", "\345\221\250\344\272\224",nullptr));
lblWeek5_4->setText(QApplication::translate("Weather", "\345\221\250\345\205\255",nullptr));
lblDate0_4->setText(QApplication::translate("Weather", "01/01",nullptr));
lblDate1_4->setText(QApplication::translate("Weather", "01/02",nullptr));
lblDate2_4->setText(QApplication::translate("Weather", "01/03",nullptr));
lblDate3_4->setText(QApplication::translate("Weather", "01/04",nullptr));
lblDate4_4->setText(QApplication::translate("Weather", "01/05",nullptr));
lblDate5_4->setText(QApplication::translate("Weather", "01/06",nullptr));
lblTypeIcon0_4->setText(QString());
lblTypeIcon4_4->setText(QString());
lblTypeIcon2_4->setText(QString());
lblTypeIcon1_4->setText(QString());
lblTypeIcon3_4->setText(QString());
lblType5_4->setText(QApplication::translate("Weather", "\346\232\264\351\233\250",nullptr));
lblType3_4->setText(QApplication::translate("Weather", "\345\244\232\344\272\221",nullptr));
lblType2_4->setText(QApplication::translate("Weather", "\345\244\232\344\272\221",nullptr));
lblType0_4->setText(QApplication::translate("Weather", "\346\231\264",nullptr));
lblType1_4->setText(QApplication::translate("Weather", "\345\260\217\351\233\250",nullptr));
lblTypeIcon5_4->setText(QString());
lblType4_4->setText(QApplication::translate("Weather", "\344\270\255\351\233\250",nullptr));
lblQuality0_4->setText(QApplication::translate("Weather", "\344\274\230",nullptr));
lblQuality1_4->setText(QApplication::translate("Weather", "\350\211\257",nullptr));
lblQuality2_4->setText(QApplication::translate("Weather", "\350\275\273\345\272\246",nullptr));
lblQuality3_4->setText(QApplication::translate("Weather", "\344\270\255\345\272\246",nullptr));
lblQuality4_4->setText(QApplication::translate("Weather", "\351\207\215\345\272\246",nullptr));
lblQuality5_4->setText(QApplication::translate("Weather", "\344\270\245\351\207\215",nullptr));
lblHighCurve_4->setText(QString());
lblLowCurve_4->setText(QString());
lblFx0_4->setText(QApplication::translate("Weather", "\344\270\234\351\243\216",nullptr));
lblFx1_4->setText(QApplication::translate("Weather", "\344\270\234\345\214\227\351\243\216",nullptr));
lblFx2_4->setText(QApplication::translate("Weather", "\350\245\277\345\214\227\351\243\216",nullptr));
lblFx3_4->setText(QApplication::translate("Weather", "\350\245\277\345\214\227\351\243\216",nullptr));
lblFx4_4->setText(QApplication::translate("Weather", "\344\270\234\345\215\227\351\243\216",nullptr));
lblFx5_4->setText(QApplication::translate("Weather", "\350\245\277\351\243\216",nullptr));
lblFl0_4->setText(QApplication::translate("Weather", "2\347\272\247",nullptr));
lblFl1_4->setText(QApplication::translate("Weather", "3\347\272\247",nullptr));
lblFl2_4->setText(QApplication::translate("Weather", "2\347\272\247",nullptr));
lblFl3_4->setText(QApplication::translate("Weather", "1\347\272\247",nullptr));
lblFl4_4->setText(QApplication::translate("Weather", "2\347\272\247",nullptr));
lblFl5_4->setText(QApplication::translate("Weather", "2\347\272\247",nullptr));
#endif
// 通用的代码
} // retranslateUi
};
namespace Ui {
class Weather: public Ui_Weather {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_WEATHER_H
UI
效果
注意
- 环境,开篇已经描述,主要在
ui_weather.h
, 如果还是不行,就直接删除ui_weather.h
,再构造就行 - 静态变量,
weathertool.h
获取城市编码工具类
weather.h
//不能再次包含头文件,weather.h多次包含,weathertool.h也会多次包含
//#include "weathertool.h"
weather.cpp
#include "weathertool.h"
// 在头文件中定义了静态变量,然后在多个源文件中包含了这个头文件,
// 就会出现同一个变量被多次定义的情况,从而导致链接错误,所以放在weather.cpp中
笔记
与源码一个路径
源码
有道云: Qt天气预报