widget.h
#include <QWidget>
#include<QTimer>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
protected:
void timerEvent(QTimerEvent *);
private:
QTimer *timer;
int timeId_1000;
int timeId_3000;
};
widget.cpp
#include "widget.h"
#include<QTimerEvent>
#include<QDebug>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
timer=new QTimer(this);
timer->setInterval(1000);
timer->start();
// connect(timer, SIGNAL(timeout()), this, SLOT(close()));
timeId_1000 = startTimer(1000);
timeId_3000 = startTimer(3000);
}
Widget::~Widget()
{
}
void Widget::timerEvent(QTimerEvent *event)
{
static int counter = 0;
if( event->timerId() == timeId_1000 )
{
qDebug()<<"1000 timeout";
counter++;
if(counter == 5)
{
killTimer(timeId_1000);
}
}
// if(event->timerId() == timeId_3000)
// {
// qDebug()<<"3000 timeout";
// counter++;
// if(counter == 5)
// {
// killTimer(timeId_3000);
// }
// }
}