PDA

View Full Version : Scheduling long terms events in Qt



KanadaKid
11th October 2010, 23:37
Hi,

I'm designing an alarm clock type application in-house. The program will basically display a weekly schedule, and will allow users to enter an alarm to go off on a given day at a given time. The current implementation uses QTimer objects that are to go off on that date. I manually calculate the amount of days, hours, and minutes to add to the current date and time, and then find the delta between the target date and time and the current date and time.

Of course, this implementation has many flaws; for example, if the user changes the system date or time, then the timers all need to be updated. My question is: is there a better way to do this?

I'm trying to target Windows, Linux and Mac, so I'm trying to keep the code as portable as possible. Does anyone have any suggestions?

Thank you!

SixDegrees
12th October 2010, 00:33
Do everything in GMT.

tbscope
12th October 2010, 05:49
Why calculate everything?

Use one timer and a QDateTime object for each alarm date.
In the slot connected to the timer timeout signal, compare the currentdate and time to the list of QDateTime object (alarm dates). When one matches, handle it.