Qt day3

QQ录屏20230518202541

Qt day3_第1张图片

 widget.h

#ifndef WIDGET_H
#define WIDGET_H
#include 
#include 
#include 
#include 
#include 
#include 
#include 
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
    void timerEvent(QTimerEvent *event);

private slots:

    void on_stBtn_clicked();

    void on_clBtn_clicked();

private:
    Ui::Widget *ui;
    int tid;
    QTextToSpeech *speech;
};
#endif // WIDGET_H

widget.h

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

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    tid=startTimer(1000);
    speech=new QTextToSpeech(this);
    ui->clBtn->setDisabled(true);

}

Widget::~Widget()
{
    delete ui;
}
void Widget::timerEvent(QTimerEvent *event)
{

    QDateTime sys_dt=QDateTime::currentDateTime();
    QString dt=sys_dt.toString("hh:mm:ss");
    ui->datelabel->setAlignment(Qt::AlignCenter);

    ui->datelabel->setText(dt);
    if(ui->datelabel->text()==ui->lineEdit->text())
    {
        ui->textEdit->setText("你这个年纪,你怎么睡得着的");
        speech->say(ui->textEdit->toPlainText());
    }
}
void Widget::on_stBtn_clicked()
{
    ui->stBtn->setDisabled(true);
    ui->clBtn->setDisabled(false);
}

void Widget::on_clBtn_clicked()
{
    ui->clBtn->setDisabled(true);
    ui->lineEdit->clear();
    ui->stBtn->setDisabled(false);
    ui->textEdit->clear();
}

你可能感兴趣的:(qt,ubuntu,c++)