C++闹钟设置

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //给定时器实例化对象
    t1 =new    QTimer(this);
    //将定时器的timeout信号连接到自定义槽函数中
    connect(t1,&QTimer::timeout,this,&Widget::on_timeout);
    t1->start(1000);//每秒刷新一次
    //给定时器实例化对象
    t2 =new    QTimer(this);
    //将定时器的timeout1信号连接到自定义槽函数中
    connect(t2,&QTimer::timeout,this,&Widget::on_timeout1);
}

Widget::~Widget()
{
    delete ui;
}



//当前时间
void Widget::on_timeout()
{
    //获取系统当前时间
    QTime sys_t =QTime::currentTime();
    //将系统时间转换成字符串
    time =sys_t.toString("hh:mm");

    //对字符串进行设置

    if(showFlag)
    {
        time[2]=':';
        showFlag=false;
    }else
    {
        time[2]=' ';
        showFlag =true;
    }

         //展示到ui界面
    ui->lcd_colock->display(time);


}

void Widget::on_timeout1()
{

    if( time==ui->textEdit_3->toPlainText())
    {
        //播报
        speech  =new QTextToSpeech(this);
         speech->say(ui->textEdit->toPlainText());
    }

}
//设定时间
void Widget::on_textEdit_3_copyAvailable(bool b)
{
    if(ui->pushButton->text() == "启动")
    {
        // 获取用户输入的时间
        QString strTime = ui->textEdit_3->toPlainText();

        // 将时间转换成 QTime 格式
        QTime setTime = QTime::fromString(strTime, "hh:mm:ss");


    }
}

//启动
void Widget::on_pushButton_clicked()
{
    t2->start(1000);

}
//关闭
void Widget::on_pushButton_2_clicked()
{
     this->close();
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值