-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
64 lines (54 loc) · 1.83 KB
/
Copy pathmainwindow.cpp
File metadata and controls
64 lines (54 loc) · 1.83 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>
#include <QDebug>
#include "timer.h"
#include <QTime>
#include <QtTextToSpeech/QTextToSpeech>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
Timer *timekeeper= new Timer();
connect(ui->pushButtonStart,SIGNAL(clicked()),this,SLOT(startTime()));
// connect(ui->pushButtonStart,SIGNAL(clicked()),timekeeper,SLOT(start()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::startTime()
{
qCritical()<<"updated val called";
ui->pushButtonStart->setEnabled(false);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
timer->start(1000);
QTime *t = new QTime(0,25,0);
ui->labelTime->setText(t->toString("mm:ss"));
/* QTime currTime=QTime::currentTime();
int mintonextHour=60-currTime.toString("m").toInt();
QTimer::singleShot(mintonextHour*60000,this,SLOT(singleFired()));*/
}
void MainWindow::singleFired()
{
qCritical()<<"Entered singleFired at"+QTime::currentTime().toString();
QTextToSpeech *qts=new QTextToSpeech();
QVector<QVoice> availVoice=qts->availableVoices();
qts->setVoice(availVoice.at(1));
qts->say("It is "+QTime::currentTime().toString("HA"));
// so now the time should be HH:00 now we have to schedule it every hour
//handles the rescheduling
QTimer *qt = new QTimer(this);
connect(qt, SIGNAL(timeout()), this, SLOT(singleFired()));
qt->start(60*60000);
}
void MainWindow::showTime()
{
QTime currLabel = QTime::fromString(ui->labelTime->text(),"mm:ss");
// qCritical()<<currLabel.toString("mm:ss");
currLabel=currLabel.addSecs(-1);
// qCritical()<<currLabel.toString("mm:ss");
ui->labelTime->setText(currLabel.toString("mm:ss"));
}