QT 4 日目:

アラームイベント:

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

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //语音播报
    speech =new QTextToSpeech(this);
    //关于界面标题
    qDebug()<<this->windowTitle();
    this->setWindowTitle("闹钟事件");
    //设置窗口图标
    this->setWindowIcon(QIcon("D:\\C++\\23021C++\\1.jpg"));
    //this->setFixedSize(this->size());
    //对行编辑器进行设置
    ui->led->setPlaceholderText("小时/分钟");
    //connect(timer, &QTimer::timeout, this, &Widget::on_timeout_slot);
    //ui->textEdit->setText("放学别走,一起出去玩");
    event_timer=this->startTimer(1000);

}

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

void Widget::on_startlab_clicked()
{
    QString s=ui->led->Text();
    test = this->startTimer(1000);
}

void Widget::on_closelab_clicked()
{
    //停止闹钟事件
    this->killTimer(event_timer);
    ui->led->clear();
}

void Widget::timerEvent(QTimerEvent *event)
{
    //执行不同定时器进行区分,使用event成员函数来
    if(event->timerId()==event_timer)
    {
        //通过QdataTime的静态成函数获取系统当前时间
        QTime sys=QTime::currentTime();
        //将系统时间转换字符串
        QString date=sys.toString("hh:mm:ss:zzz");
        //字符串展示到lab中
        ui->timelab->setText(date);
    }

    if(event->timerId()==test)
    {
        QString str=QTime::currentTime().toString("hh:mm:ss:zzz");
        if(str == s)
        {
           ui->textEdit->setText("放学别走,一起出去玩");
            speech->say(ui->textEdit->toPlainText());
        }
    }
}

 

おすすめ

転載: blog.csdn.net/weixin_57039874/article/details/130456391