华清 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

相关推荐
鲸屿19510 分钟前
python之socket网络编程
开发语言·网络·python
没有梦想的咸鱼185-1037-166336 分钟前
基于R语言机器学习方法在生态经济学领域中的实践技术应用
开发语言·机器学习·数据分析·r语言
a5876938 分钟前
消息队列(MQ)初级入门:详解RabbitMQ与Kafka
java·分布式·microsoft·面试·kafka·rabbitmq
千里码aicood1 小时前
【springboot+vue】党员党建活动管理平台(源码+文档+调试+基础修改+答疑)
java·数据库·spring boot
Chan161 小时前
【智能协同云图库】基于统一接口架构构建多维度分析功能、结合 ECharts 可视化与权限校验实现用户 / 管理员图库统计、通过 SQL 优化与流式处理提升数据
java·spring boot·后端·sql·spring·intellij-idea·echarts
先做个垃圾出来………1 小时前
差分数组(Difference Array)
java·数据结构·算法
向上的车轮1 小时前
基于go语言的云原生TodoList Demo 项目,验证云原生核心特性
开发语言·云原生·golang
The Chosen One9851 小时前
C++ : AVL树-详解
开发语言·c++
SNAKEpc121381 小时前
QML和Qt Quick
c++·qt
PH_modest1 小时前
【Qt跬步积累】—— 初识Qt
开发语言·qt