QT day4

闹钟:设定时间后关闭键变为可用   闹钟时间到后语音播报文本内容

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

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->closeBtn->setEnabled(false);
    //文本框内容
    ui->timeEdit->setPlaceholderText("设定时间");
}

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

void Widget::on_eventBtn_clicked()
{
    if(ui->eventBtn->text() == "启动")
    {
        //启动一个定时器
        event_timer = this->startTimer(1000);
        ui->eventBtn->setText("关闭");
    }
    else
    {
        //执行关闭一个定时器
        this->killTimer(event_timer);
        //将按钮文本内容改为"启动"
        ui->eventBtn->setText("启动");
    }
}

void Widget::timerEvent(QTimerEvent *e)
{
    //判断是哪个定时器到位
    if(e->timerId() == event_timer)
    {
        //获取系统日期时间
        QDateTime sys_dt = QDateTime::currentDateTime();
        //将该时间转换为字符串并展示到ui界面上
        ui->eventLab->setText(sys_dt.toString("yyyy-MM-dd hh:mm:ss"));
        ui->textEdit->setText("好好学习,天天向上");
        time=sys_dt.toString("yyyy-MM-dd hh:mm:ss");
        QString settime = ui->timeEdit->toPlainText();
        if(settime == time)
        {
            qDebug() << "11111";
        }
    }
}

void Widget::on_startBtn_clicked()
{
    QPushButton *button = ui->closeBtn;
    button->setEnabled(true);
}

        

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值