- 论坛徽章:
- 0
|
hello.h---------------------------
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
class myMainWindow : public QWidget
{
Q_OBJECT
public:
myMainWindow();
~myMainWindow();
public slots:
void bEvent(); //按钮事件
void getTimeout();
private:
QLabel *lb;
QMovie *dogImg;
void paintEvent(QPaintEvent *);
int fd;
QTimer *wdgTimer;
QPushButton *b_on1;
QLCDNumber *lcdnum;
int timeout;
};
hello.cpp---------------------------
#include "hello.h"
#include
#include
#include
#include
#include
#include
#include
#include "ioctl.h"
#define WATCHDOG_IOCTL_BASE 'W'
#define WDIOC_SETTIMEOUT _IOWR(WATCHDOG_IOCTL_BASE, 6, int)
#define WDIOC_GETTIMEOUT _IOR(WATCHDOG_IOCTL_BASE, 7, int)
myMainWindow::myMainWindow()
{
setMinimumSize(220,280);
setMaximumSize(220,280);
b_on1 = new QPushButton("feed",this);
b_on1->setGeometry(10,180,200,30);
b_on1->setFont(QFont("Times",15,QFont::Bold));
lcdnum = new QLCDNumber(this);
lcdnum->setGeometry(150,110,50,50);
lcdnum->setSegmentStyle(QLCDNumber::Filled);
lcdnum->display(0);
lb = new QLabel(this);
dogImg = new QMovie("dog.gif");
lb->setGeometry(30,110,70,48);
lb->setMovie(*dogImg);
// dogImg->step(1);
//只能分辨出深色和浅色,所以要想显示浅色的前景色就得将
//背景色弄成深色
fd = open("/dev/misc/watchdog",O_RDWR);
if (fd start(1000); //开启
timeout--;
connect(b_on1,SIGNAL(clicked()),this,SLOT(bEvent()));
}
myMainWindow::~myMainWindow()
{
write(fd,"V",1); //停止看门狗
::close(fd);
}
void myMainWindow::paintEvent(QPaintEvent *)
{
QPixmap img1("notice.png");
img1.setMask(img1.createHeuristicMask());
QPixmap img3("designed.png");
img3.setMask(img3.createHeuristicMask());
QPainter paint;
paint.begin(this);
paint.drawPixmap(10,10,img1);
paint.drawPixmap(10,217,img3);
paint.end();
}
void myMainWindow::bEvent()
{
write(fd,"a",1); //喂狗
ioctl(fd,WDIOC_GETTIMEOUT,&timeout);
}
void myMainWindow::getTimeout()
{
wdgTimer->stop();
lcdnum->display(timeout--);
wdgTimer->start(1000);
}
int main(int argc,char **argv)
{
QApplication a(argc,argv);
myMainWindow w;
a.setMainWidget(&w);
w.show();
a.exec();
}
源码打包:
http://blogimg.chinaunix.net/blog/upfile2/091201173239.gz
![]()
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93291/showart_2108687.html |
|