-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmytimer.cpp
More file actions
29 lines (28 loc) · 828 Bytes
/
mytimer.cpp
File metadata and controls
29 lines (28 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "mytimer.h"
#include <QTime>
#include <QDebug>
#include <QTimeEdit>
MyTimer::MyTimer(QObject *parent) :
QTimer(parent)
{
this->setSingleShot(true);
}
void MyTimer::setTimer(const QTime &time){
int remainingTime = QTime::currentTime().msecsTo(time);
if(remainingTime>=0){
qDebug()<<"Timer: "<<remainingTime;
this->start(remainingTime);
}else{
qDebug()<<"Timer: "<<(86400000+remainingTime);
this->start(86400000+remainingTime);
}
}
void MyTimer::activeTimer(bool active){
QTimeEdit *timeEdit = (QTimeEdit*)this->parent();
if(active){
QObject::connect(timeEdit,SIGNAL(timeChanged(QTime)),this,SLOT(setTimer(QTime)));
this->setTimer(timeEdit->time());
}else{
timeEdit->disconnect();
}
}