使用qt搭建一个简易的闹钟系统
#include "second.h"
#include "ui_second.h"
second::second(QWidget *parent) :
QWidget(parent),
ui(new Ui::second)
{
ui->setupUi(this);
this->setWindowFlag(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground);
timeid1 = startTimer(1000);
ui->lab_currenttime->setAlignment(Qt::AlignCenter);
}
second::~second()
{
delete ui;
}
void second::timerEvent(QTimerEvent *e)
{
if(e->timerId() == timeid1)
{
QTime qt = QTime::currentTime();
QString st = qt.toString();
ui->lab_currenttime->setText(st);
if(alarmtime==st)
{
QString say = ui->lab_say->text();
speaker = new QTextToSpeech(this);
speaker->say(say);
}
}
}
void second::start()
{
this->show();
}
void second::on_btn_settime_clicked()
{
alarmtime = ui->lineEdit_alarmtime->text();
QMessageBox::information(this,"tip","闹钟设置成功");
}