Qt学习:QTimerEvent定时器事件的处理程序代码示例

  

<强>重要函数:,
1. int开始时间(int);//设置定时器,返回一个ld只
2. int事件→timerld ();//返回当前的ld只
3。消磨时间的空白(int);//停止定时器。

<人力资源/>

首先从Qt设计师中拖拽出三个按钮,由于只是演示定时器事件的使用,所以就没有布局的需要了只
# ifndef  C_H # define  C_H # include  & lt; QtWidgets/QMainWindow> # include “ui_c.h”# include  & lt; QLabel> # include  & lt; QTimerEvent> class  c :, public  QMainWindow   {   ,,,Q_OBJECTpublic:,,,, c (QWidget  * parent =, 0);   ,,,~ c();保护:   ,,,//这是一个虚函数,从QEvent继承而来只,,,void  timerEvent (QTimerEvent *事件);private 槽:,,,,void  startTimerSlot (),,,,, void  stopTimerSlot();私人:   ,,,Ui: cClass  Ui,,,,, int  m_lamp;,,,, bool  m_lampStatus =,假;   };# endif //, C_H12345678910111213141516171819202122232425262728293031 <人力资源/>

最后”是主要的。cpp”的代码:

# include “刘昀”# include  & lt; QtWidgets/QApplication> int 主要(int 命令行参数个数,char  * argv [])   {   ,,,QApplication (命令行参数个数,argv);   ,,,c  w;   ,,,w.show (),,,,, return  a.exec ();   }


Qt学习:QTimerEvent定时器事件的处理程序代码示例