?? weatherballoon.cpp
字號:
#include <qdatetime.h>#include <qhostaddress.h>#include <cstdlib>using namespace std;#include "weatherballoon.h"WeatherBalloon::WeatherBalloon(QWidget *parent, const char *name) : QPushButton(tr("Quit"), parent, name), socketDevice(QSocketDevice::Datagram){ socketDevice.setBlocking(false); myTimerId = startTimer(5 * 1000);}void WeatherBalloon::timerEvent(QTimerEvent *event){ if (event->timerId() == myTimerId) { QByteArray datagram; QDataStream out(datagram, IO_WriteOnly); out.setVersion(5); out << QDateTime::currentDateTime() << temperature() << humidity() << altitude(); socketDevice.writeBlock(datagram, datagram.size(), 0x7F000001, 5824); } else { QPushButton::timerEvent(event); }}double WeatherBalloon::temperature() const{ return -20.0 + (2.0 * rand() / (RAND_MAX + 1.0));}double WeatherBalloon::humidity() const{ return 20.0 + (2.0 * rand() / (RAND_MAX + 1.0));}double WeatherBalloon::altitude() const{ return 7000 + (100.0 * rand() / (RAND_MAX + 1.0));}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -