免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1737 | 回复: 0
打印 上一主题 下一主题

qt 看门狗 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-01 17:46 |只看该作者 |倒序浏览

                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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP