Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTimer start specific time

Tags:

c++

qt

I try to start timer at specific time like 02:30. Every day it starts at 02.30.

Is it possible? Do you have any idea?

Thank a lot.

like image 976
selda Avatar asked Mar 01 '11 07:03

selda


2 Answers

QTimer doesn't handle specific times of day natively, but you could use it in conjunction with QDateTime to get what you want. That is, use QDateTime objects to figure out how many seconds are between (right now) and 2:30 (QDateTime::msecsTo() looks particularly appropriate here), then set your QTimer to go off after that many seconds. Repeat as necessary.

like image 55
Jeremy Friesner Avatar answered Sep 17 '22 16:09

Jeremy Friesner


Depending on the required resolution, you could use an ordinary QTimer that fires let's say every minute.
In the timerEvent, you could check if you are on the right time (using QDateTime), and trigger the necessary event.

like image 45
Kurt Pattyn Avatar answered Sep 17 '22 16:09

Kurt Pattyn