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

相关推荐
忒可君4 分钟前
C# winform FTP功能
开发语言·windows·c#
六千江山20 分钟前
从字符串中提取符合规则的汽车车牌
java
33255_40857_2805928 分钟前
从韩立结婴看Java进阶:一个10年老码农的修仙式成长指南
java
赵星星52028 分钟前
透彻理解Java中的深拷贝与浅拷贝:从误区到最佳实践
java·后端
minji...29 分钟前
C++ string类(STL简介 , string类 , 访问修改字符)
开发语言·c++
心月狐的流火号30 分钟前
Java CompletableFuture 核心API
java
Forward♞35 分钟前
Qt——文件操作
开发语言·c++·qt
黑客影儿40 分钟前
Java技术总监的成长之路(技术干货分享)
java·jvm·后端·程序人生·spring·tomcat·maven
京东云开发者1 小时前
EXCEL导入—设计与思考
java·架构
Warren981 小时前
软件测试-Selenium学习笔记
java·javascript·笔记·学习·selenium·测试工具·安全