Created
January 23, 2013 11:54
-
-
Save lamprosg/4604750 to your computer and use it in GitHub Desktop.
Qt - Simple Timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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