I have a QTimeEdit which I want to set to some value and the each second I want to decrease by 1 the value that shows the QTimeEdit. So when it will be 0, the I want to have a QMeesageBox that says "Your time is off.". Can I some how do this with QTimeEdit interface, or I should use QTimer?
+2
A:
You can use QTimeEdit
for displaying the time but you will have to use QTimer
to decrease the time every second.
You can do something like this:
timeEdit->setTime(...); //set initial time
QTimer timer;
timer.start(1000); //timer will emit timeout() every second
connect(&timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
void slotTimeout()
{
QTime time = timeEdit->time().addSecs(-1);
timeEdit->setTime(time);
if (time == QTime(0, 0))
//time is zero, show message box
}
Job
2010-06-17 07:57:52
addSecs(int s) does not work. I am using Qt 4.6.2. Has anyone encountered to this problem?
Narek
2010-06-18 18:09:22
Woops sorry made an error in my answer. It's fixed now.
Job
2010-06-18 19:29:00
Also I have put 2 minutes, it comes to 0 sec and there is no entrance to the "if" statement. Can't understand why.
Narek
2010-06-19 06:44:35
When I use QTime its "mds" field is becoming -1. So you need to call QTime(0,0) constructor! Please change your answer in order to accept it. BTW where are my votes?? :)
Narek
2010-06-19 07:29:38
Yeah sorry I really should check my answers before posting them:) It's fixed now. What votes do you mean?
Job
2010-06-19 10:04:47
Up votes :))))))))))
Narek
2010-06-19 10:08:55
On the answer? Well I guess somebody downvoted it then. Not to worry, though, there are still 2 upvotes:)
Job
2010-06-19 10:26:12