Skip to content

Instantly share code, notes, and snippets.

@lamprosg
Created January 23, 2013 11:54
Show Gist options
  • Select an option

  • Save lamprosg/4604750 to your computer and use it in GitHub Desktop.

Select an option

Save lamprosg/4604750 to your computer and use it in GitHub Desktop.
Qt - Simple Timer
#include "mytimer.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Mytimer mtimer; //Costructor will fire where the code is. That's it
return a.exec();
}
#include "mytimer.h"
Mytimer::Mytimer()
{
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(MySlot()));
//Start the timer
timer->start(1000); //1000 msec
}
//Slot implementation
void MyTimer::MySlot()
{
//Timer executed
}
//Timer Class with Base Class QObject
class Mytimer : public QObject
{
Q_OBJECT
public:
Mytimer();
QTimer *timer;
public slots:
void MySlot();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment