首页 > 其他 > 详细

Qt类中使用定时器

时间:2015-08-12 21:27:52      阅读:235      评论:0      收藏:0      [点我收藏+]

  QT定时器只能使用在进程或线程中。

  QT类中如果需要定时器,可以把定时工作安排在一个线程中执行。

class aaa : public QThread
{
    Q_OBJECT      
     ...
protected:
     //重写run函数
     void run();
public slots:
     void timerOut();
private:
     QTimer *timer;  
}

aaa::aaa(QThread *parent):QThread(parent)
{
     timer = new QTimer(0);
     connect(timer,SIGNAL(timeout()),this,SLOT(timerOut()),Qt::DirectConnection);
     timer->start(xxx);
}

void aaa::run()
{
     exec();  
}

void aaa::timerOut()
{
   ....
}


int main()
{
     QCoreApplication a(); 
     aaa *pt = new aaa();
     pt->start();
     return a.exec();
} 

  

Qt类中使用定时器

原文:http://www.cnblogs.com/GB-B/p/4725342.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!