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

}
相关推荐
用户805533698034 天前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner4 天前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz9 天前
QML Hello World 入门示例
qt
xcyxiner12 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner13 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner13 天前
DicomViewer (添加模型类)3
qt
xcyxiner14 天前
DicomViewer (目录调整) 2
qt
xcyxiner14 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
桥田智能16 天前
桥田智能 QT-650S:面向白车身焊装的 800kg 重载快换解决方案
开发语言·qt·系统架构
森G16 天前
75、服务器源码解析---------云视频服务项目
linux·服务器·网络·c++·qt