Qt实现天气预报与PM2.5监测系统(8)一周天气
2017-04-25 11:25
225 查看
Qt实现天气预报与PM2.5监测系统(8)一周天气
程序界面
界面上共显示六天的天气情况每一列都是类ShowWeek的一个实例化,程序中由对象数组showWeek[6]
//初始化一周天气界面,postion value int x = 250; for(int i=0;i<MAX_DAY;i++){ showWeek[i] = new DayData(this); showWeek[i]->setVal(x,100,QString::number(i)); showWeek[i]->hide(); x += 120; } #ifndef DAYDATA_H #define DAYDATA_H #include <QWidget> #include "showlabel.h" class DayData : public QWidget { Q_OBJECT public: DayData(QWidget *parent = 0); void setVal(int x, int y,QString wicon); void updateVal(QString *daily); signals: public slots: private: ShowLabel *weekday; ShowLabel *date; ShowLabel *temp; ShowLabel *weather; ShowLabel *wind; ShowLabel *windpower; QLabel *weatherIcon; }; #endif // DAYDATA_H #include "daydata.h" DayData::DayData(QWidget *parent) : QWidget(parent) { this->setMinimumSize(1024,600); this->setMaximumSize(1024,600); } void DayData::setVal(int x, int y,QString wicon) { QDateTime time = QDateTime::currentDateTime();//获取系统现在的时间 weekday = new ShowLabel(this); weekday->addFontSize(2); //weekday->setGeometry(QRect(250, 80, 100, 40)); weekday->setGeometry(QRect(x, y, 100, 40)); weekday->setAlignment(Qt::AlignHCenter); weekday->setText(tr("今天")); date = new ShowLabel(this); date->addFontSize(2); date->setGeometry(QRect(x, y+40, 100, 40)); date->setAlignment(Qt::AlignHCenter); date->setText(time.toString("M月d日")); weatherIcon = new QLabel(this); weatherIcon->setGeometry(QRect(x+10, y+100, 70, 70)); QString iconStr = ":/images/weathercn02/" + wicon + ".png" ; weatherIcon->setPixmap(QPixmap(iconStr)); weatherIcon->setScaledContents(true); temp = new ShowLabel(this); temp->addFontSize(3); temp->setGeometry(QRect(x, y+210, 100, 40)); temp->setAlignment(Qt::AlignHCenter); temp->setText(tr("2-9℃")); weather = new ShowLabel(this); weather->addFontSize(3); weather->setGeometry(QRect(x, y+250, 100, 40)); weather->setAlignment(Qt::AlignHCenter); weather->setText(tr("晴")); wind = new ShowLabel(this); wind->addFontSize(-2); wind->setGeometry(QRect(x, y+340, 100, 40)); wind->setAlignment(Qt::AlignHCenter); wind->setText(tr("风")); windpower = new ShowLabel(this); windpower->addFontSize(0); windpower->setGeometry(QRect(x, y+380, 100, 40)); windpower->setAlignment(Qt::AlignHCenter); windpower->setText(tr("3级")); } void DayData::updateVal(QString *daily) { weekday->setText(daily[1]); date->setText(daily[0].mid(5)); QString iconStr = ":/images/weathercn02/" + daily[5] + ".png" ; weatherIcon->setPixmap(QPixmap(iconStr)); temp->setText(daily[2]+tr("-")+daily[3]+tr("℃")); weather->setText(daily[4]); wind->setText(daily[6]); windpower->setText(daily[7]); }
界面数据更新
//更新显示的数据 if(temp_timer>=300 || sysSet->getFlagVal()==1){ ... this->get_week_value(); for(int i=0;i<MAX_DAY;i++){ showWeek[i]->updateVal(weekArr[i]); } ... }
解析数据
python程序从云端获取的一周天气数据写入文件week_file,通过get_week_value方法从文件中解析出有效的数据到QString数组中。
int SysDialog::get_week_value(void) { FILE *fp; char read_buf[LEN]; char buf[LEN]; char *p,*temp; int i=0,len=0,daily=0,item=0; bzero(read_buf,LEN); fp = fopen(WEEK_FILE,"r"); if(NULL == fp) return -1; len = fread(read_buf,1,1024,fp); // len= strlen(read_buf); printf("%s\n,len=%d\n",read_buf,len); p=read_buf; bzero(buf,LEN); temp = buf; for(i=0;i<len;i++){ if(p[i] != '$'){ *temp = p[i]; temp++; }else{ *temp=0; temp=buf; weekArr[daily][item] = QString(buf); if(++item > 7){ item = 0; if(++daily > 5) break; } } } return 0; }
相关文章推荐
- Qt实现天气预报与PM2.5监测系统(4)DHT11模块驱动
- Qt实现天气预报与PM2.5监测系统(3)PM2.5模块程序
- Qt实现天气预报与PM2.5监测系统(7)今日天气
- Qt实现天气预报与PM2.5监测系统(1)项目介绍
- Qt实现天气预报与PM2.5监测系统(10)系统设置
- Qt实现天气预报与PM2.5监测系统(9)空气质量
- Qt实现天气预报与PM2.5监测系统(5)天气预报接口
- Qt实现天气预报与PM2.5监测系统(6)系统界面设计
- Qt实现天气预报与PM2.5监测系统(2)Qt运行环境
- Qt实现简易天气预报(解析的是json数据)
- 天气预报经常查,使用Web Service实现
- Jquery和雅虎的YQL服务实现天气预报功能!
- 找到的“分布式入侵监测系统设计与实现”论文
- 实现天气预报功能
- 实现获取指定城市的天气预报
- Ajax实现天气预报功能
- node.js 中国天气预报 简单实现
- 天气预报模块的实现分析
- 基于HTML5 geolocation 实现的天气预报功能
- Qt个性化系统托盘的实现(电脑管家)