码迷,mamicode.com
首页 > 其他好文 > 详细

Qt类中使用定时器

时间:2015-08-12 21:30:21      阅读:143      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!