Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- QTimer *timer = new QTimer;
- timer->start(10);
- connect(timer,SIGNAL(timeout()),someObject,SLOT(someFunction()));
- QApplication app(argc, argv);
- [...]
- app.exec();
- while(1)
- {
- SleepUntilThereIsSomethingToDo(); // not a real function name!
- DoTheThingsThatNeedDoingNow(); // this is also a name I made up
- if (timeToQuit) break;
- }
- int select(int nfds,
- fd_set *readfds,
- fd_set *writefds,
- fd_set *exceptfds,
- struct timeval *timeout);
- void SleepUntilThereIsSomethingToDo()
- {
- struct timeval now = gettimeofday(); // get the current time
- struct timeval nextQTimerTime = [...]; // time at which we want to emit a timeout() signal, as was calculated earlier inside QTimer::start()
- struct timeval maxSleepTimeInterval = (nextQTimerTime-now);
- select([...], &maxSleepTimeInterval); // sleep until the appointed time (or until I/O arrives, whichever comes first)
- }
- void DoTheThingsThatNeedDoingNow()
- {
- // Is it time to emit the timeout() signal yet?
- struct timeval now = gettimeofday();
- if (now >= nextQTimerTime) emit timeout();
- [... do any other stuff that might need doing as well ...]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement