Have a look into QTimer
Q_OBJECT
public:
MyClass();
public slots:
void myTimerHandler();
private:
qint32 counter;
};
// .. cont
MyClass::MyClass()
{
counter = 0;
connect(timer,SIGNAL(timeout()), this ,SLOT(myTimerHandler()));
timer->start(1000); // 100 nanoseconds or 1 second interval
}
void MyClass::myTimerHandler()
{
counter++;
qDebug
() <<
QString("Time: %1 seconds").
arg(counter
);
}
class MyClass : public QObject {
Q_OBJECT
public:
MyClass();
public slots:
void myTimerHandler();
private:
QTimer * timer;
qint32 counter;
};
// .. cont
MyClass::MyClass()
{
counter = 0;
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()), this ,SLOT(myTimerHandler()));
timer->start(1000); // 100 nanoseconds or 1 second interval
}
void MyClass::myTimerHandler()
{
counter++;
qDebug() << QString("Time: %1 seconds").arg(counter);
}
To copy to clipboard, switch view to plain text mode
Bookmarks