qt+day4

cpp 复制代码
#define WIDGET_H

#include <QWidget>
#include <QTimerEvent>
#include <QTimer>
#include <QTime>
#include <QTextToSpeech>

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 *e);

private slots:
    void on_sbtn_clicked();

    void on_cbtn_clicked();

private:
    Ui::Widget *ui;
    int id;

    QTextToSpeech *speech;

};
#endif // WIDGET_H
cpp 复制代码
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setFixedSize(980,460);


    speech = new QTextToSpeech(this);

}

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

void Widget::timerEvent(QTimerEvent *e)
{
    //获取系统时间
        QTime systime = QTime::currentTime();

        //将系统时间转换
        QString s = systime.toString("hh:mm:ss");

        //将转换后的系统时间放入Label中
        ui->timelabel->setText(s);

        //居中显示
        ui->timelabel->setAlignment(Qt::AlignCenter);

        //比对闹钟时间和系统时间,如果相等,则播报闹钟
        if(ui->tdeit->text() == s)
        {
            for(int i=0;i<3;i++)
            {
                speech->say(ui->speechlabel->text());
            }
        }
}





void Widget::on_sbtn_clicked()
{
    id = startTimer(1000);

}

void Widget::on_cbtn_clicked()
{
    killTimer(id);

}
相关推荐
blasit2 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
范特西.i7 天前
QT聊天项目(8)
开发语言·qt
枫叶丹48 天前
【Qt开发】Qt界面优化(七)-> Qt样式表(QSS) 样式属性
c语言·开发语言·c++·qt
十五年专注C++开发8 天前
Qt deleteLater作用及源码分析
开发语言·c++·qt·qobject
kangzerun8 天前
SQLiteManager:一个优雅的Qt SQLite数据库操作类
数据库·qt·sqlite
金刚狼888 天前
qt和qt creator的下载安装
开发语言·qt
追烽少年x8 天前
Qt中使用Zint库显示二维码
qt
谁刺我心8 天前
qt源码、qt在线安装器镜像下载
开发语言·qt
金刚狼888 天前
在qt creator中创建helloworld程序并构建
开发语言·qt
扶尔魔ocy8 天前
【转载】QT使用linuxdeployqt打包
开发语言·qt