QT day4

02-28 1807阅读

QT day4

#ifndef WIDGET_H
#define WIDGET_H
#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();
private:
    Ui::Widget *ui;
    int id;
    QTextToSpeech *speecher;
public:
    void timerEvent(QTimerEvent *e);
private slots:
    void on_Btn1_clicked();
};
#endif // WIDGET_H
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    speecher = new QTextToSpeech(this);
}
Widget::~Widget()
{
    delete ui;
}
//显示系统时间
void Widget::timerEvent(QTimerEvent *e)
{
    QTime sys_time = QTime::currentTime();   //获取系统时间
    QString t = sys_time.toString("hh::mm::ss");   //转换
    ui->Lab1->setText(t);    //显示
    if(ui->Lab1->text() == ui->Edit1->text())
    {
        ui->Lab3->setText("好好学习");
        speecher->say(ui->Lab3->text());
    }
}
void Widget::on_Btn1_clicked()
{
    if(ui->Btn1->text() == "启动")
    {
        id = startTimer(1000);  //让系统每隔一秒执行timerEvent函数
        ui->Btn1->setText("关闭");
    }else {
        killTimer(id);
        ui->Btn1->setText("启动");
    }
}

QT day4

VPS购买请点击我

文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

目录[+]