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

}
相关推荐
回眸不遇10 分钟前
详谈 QT 布局 QLayout::SizeConstraint 和 QSizePolicy 对 QWidget 尺寸的影响
数据库·qt·系统架构
Richard.Wong5 小时前
qt生成dll供C#调用
开发语言·qt
Infedium1 天前
Qt嵌入式开发核心亮点:线程安全硬件交互技术
开发语言·qt
秋田君1 天前
QT_QInputDialog类输入对话框
开发语言·qt
秋田君2 天前
QT_QFontDialog类字体对话框
开发语言·qt
mabing9932 天前
Qt QMessageBox、QDialogButtonBox中英文翻译动态切换
开发语言·qt
秋田君2 天前
QT_QColorDialog颜色对话框
java·数据库·qt
秋田君2 天前
QT_QT布局常用类QSplitter窗口分割类与QDockWidget窗口停靠类
开发语言·数据库·qt
Lhan.zzZ2 天前
深入理解 windeployqt:混合 C++/Qt 项目的打包指南
开发语言·c++·qt
Lhan.zzZ2 天前
QML 开发中的“陷阱”:动态模型更新时,ComboBox 索引为何总是失效?
开发语言·qt