华清 Qt day3 9月19

cpp 复制代码
QT       += core gui texttospeech

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    widget.cpp

HEADERS += \
    widget.h

FORMS += \
    widget.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
/*****************************************************************************/
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QFontDialog>
#include <QFont>
#include <QMessageBox>
#include <QDebug>
#include <QColorDialog>
#include <QColor>
#include <QFileDialog>
#include <QFile>
#include <QKeyEvent>      //键盘事件处理类的头文件
#include <QDebug>
#include <QMouseEvent>
#include <QTimerEvent>
#include <QTime>
#include <QTextToSpeech>
#include <QVoice>


QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();


private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    //重写定时器处理函数
    void timerEvent(QTimerEvent *e);

private:
    Ui::Widget *ui;

    int timer_id;       //定时器的id号

    QTextToSpeech *s;   //定义一个播报员

};
#endif // WIDGET_H

/**********************************************************************/
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    timer_id=0;
    s = new QTextToSpeech(this);  //给播报员申请空间
}

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

//启动定时器
void Widget::on_pushButton_clicked()
{
    timer_id = this->startTimer(1000);
    //功能: 启动一个定时器
    //参数: 每隔一定时间,自动调用定时器事件处理函数
}

//关闭定时器
void Widget::on_pushButton_2_clicked()
{
    this->killTimer(timer_id);
}

//定时器事件
void Widget::timerEvent(QTimerEvent *e)
{
    if(e->timerId() == timer_id)
    {
        QString userInputTime = ui->lineEdit->text();       //获取用户输入的时间
        QTime sys_t = QTime::currentTime();  //获取系统时间
        //将QTime类对象转换为字符串
        QString t = sys_t.toString("hh:mm:ss");    //转变成字符串
        ui->label->setText(t);  //打印到label栏

        if(t == userInputTime)
        {
            qDebug()<<"时间匹配成功";
            s->say(ui->textEdit->toPlainText());     //播报文本框里的内容
            this->killTimer(timer_id);       //关闭定时器
            timer_id=0;
        }
    }
}

/***********************************************************************/

QT - day3 - GitMind

面试题 - GitMind

相关推荐
RainbowSea12 小时前
12. LangChain4j + 向量数据库操作详细说明
java·langchain·ai编程
RainbowSea12 小时前
11. LangChain4j + Tools(Function Calling)的使用详细说明
java·langchain·ai编程
考虑考虑16 小时前
Jpa使用union all
java·spring boot·后端
用户37215742613516 小时前
Java 实现 Excel 与 TXT 文本高效互转
java
浮游本尊17 小时前
Java学习第22天 - 云原生与容器化
java
渣哥19 小时前
原来 Java 里线程安全集合有这么多种
java
间彧19 小时前
Spring Boot集成Spring Security完整指南
java
间彧19 小时前
Spring Secutiy基本原理及工作流程
java
Java水解20 小时前
JAVA经典面试题附答案(持续更新版)
java·后端·面试
洛小豆1 天前
在Java中,Integer.parseInt和Integer.valueOf有什么区别
java·后端·面试