7.27 作业 QT

这篇具有很好参考价值的文章主要介绍了7.27 作业 QT。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

要求:

7.27 作业 QT,qt,开发语言

 结果图:

7.27 作业 QT,qt,开发语言

clock.pro:

QT       += core gui
QT += 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

 widget.h:

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTimerEvent>  //定时器事件处理函数
#include <QTime>    //时间类
#include <QPushButton>  //按钮类头文件
#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_start_Btn_clicked();

    void on_stop_Btn_clicked();

private:
    Ui::Widget *ui;

    static int count;   //定义静态变量

    QTextToSpeech *speecher;  //定义一个播报者

    //定义一个基于事件处理的定时器id
    int tid1;
    int tid2;
};
#endif // WIDGET_H

widget.cpp:

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    tid1 = startTimer(1000);    //启动一个定时器,隔1s会自动执行timerevent函数

    //设置占位符
    ui->clock_lineEdit->setPlaceholderText("输入多少秒后开启闹铃");

    speecher = new QTextToSpeech(this);
}

int Widget::count = 0;

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

void Widget::timerEvent(QTimerEvent *event)
{
    if(event->timerId() == tid1)
    {
             //获取系统事件
          QTime sys_time = QTime::currentTime();  //QTime类对象

            //将时间转化为字符串
          QString t = sys_time.toString("hh:mm:ss");

         //将字符串展示到ui界面
          ui->time_lab->setText(t);
          ui->time_lab->setAlignment(Qt::AlignHCenter);

    }else if(event->timerId() == tid2)
    {
        count++;

        //将clock_lineEdit 的文本转化为整数
        int m = ui->clock_lineEdit->text().toInt();

        if(count == m)
        {
            //进行语音播报
            speecher->say(ui->read_textEdit->toPlainText());

            //停止计时器
            killTimer(tid2);
        }
    }

}

void Widget::on_start_Btn_clicked()
{

    //将start_Btn设置成不可用状态
    ui->start_Btn->setEnabled(false);

    //将clock_lineEdit设置成不可用状态
    ui->clock_lineEdit->setEnabled(false);

    //将stop_Btn设置成可用状态
    ui->stop_Btn->setEnabled(true);

    //启动第二个计时器
    tid2 = startTimer(1000);    //启动一个定时器,隔1s会自动执行timerevent函数

    //将count置零
    count = 0;

}

void Widget::on_stop_Btn_clicked()
{
    //停止语音播报
    speecher->stop();

    //将stop_Btn设置成不可用状态
    ui->stop_Btn->setEnabled(false);

    //将start_Btn设置成可用状态
    ui->start_Btn->setEnabled(true);
    ui->clock_lineEdit->setEnabled(true);

    //停止计时器
    killTimer(tid2);

    //将count置零
    count = 0;
}

widget.ui:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Widget</class>
 <widget class="QWidget" name="Widget">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>613</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Widget</string>
  </property>
  <widget class="QLabel" name="time_lab">
   <property name="geometry">
    <rect>
     <x>50</x>
     <y>60</y>
     <width>321</width>
     <height>161</height>
    </rect>
   </property>
   <property name="font">
    <font>
     <pointsize>22</pointsize>
     <weight>75</weight>
     <italic>false</italic>
     <bold>true</bold>
     <underline>true</underline>
    </font>
   </property>
   <property name="styleSheet">
    <string notr="true">background-color: rgb(85, 255, 255);</string>
   </property>
   <property name="text">
    <string/>
   </property>
  </widget>
  <widget class="QLineEdit" name="clock_lineEdit">
   <property name="geometry">
    <rect>
     <x>430</x>
     <y>60</y>
     <width>291</width>
     <height>71</height>
    </rect>
   </property>
   <property name="styleSheet">
    <string notr="true">background-color: rgb(255, 255, 0);</string>
   </property>
  </widget>
  <widget class="QPushButton" name="start_Btn">
   <property name="geometry">
    <rect>
     <x>430</x>
     <y>160</y>
     <width>121</width>
     <height>61</height>
    </rect>
   </property>
   <property name="text">
    <string>开始</string>
   </property>
  </widget>
  <widget class="QPushButton" name="stop_Btn">
   <property name="geometry">
    <rect>
     <x>590</x>
     <y>160</y>
     <width>121</width>
     <height>61</height>
    </rect>
   </property>
   <property name="text">
    <string>停止</string>
   </property>
  </widget>
  <widget class="QTextEdit" name="read_textEdit">
   <property name="geometry">
    <rect>
     <x>50</x>
     <y>250</y>
     <width>671</width>
     <height>341</height>
    </rect>
   </property>
   <property name="html">
    <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:18pt; color:#55ffff;&quot;&gt;故人西辞黄鹤楼,唱跳Rap打篮球。春风又绿江南岸,练习长达两年半。清明时节雨坤坤,路上行人梳中分,借问背带何处有,牧童遥指我爱坤。长江后浪推前浪,爱坤啥样我啥样。鸡冠头背带裤,我是爱坤你记住。向阳花木易为春,听说你爱蔡徐坤。小黑子树枝666,蒸虾头,好丸吗?树枝赶人,蒸五鱼,食不食油饼,我家鸽鸽在胎上拿姜拿到手软,他那么努力,这样叫我怎么荔枝?已经橘爆你了,再这样我就抱紧了,劝你苏珊,不然我们爱坤就紫砂了。&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

思维导图:

7.27 作业 QT,qt,开发语言

 文章来源地址https://www.toymoban.com/news/detail-616607.html

到了这里,关于7.27 作业 QT的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【Visual Studio】Qt 的实时绘图曲线功能,使用 C++ 语言,配合 Qt 开发串口通信界面

    知识不是单独的,一定是成体系的。更多我的个人总结和相关经验可查阅这个专栏:Visual Studio。 战斗背景:做了个串口接收界面,用来接收传输过来的信号。但是光用数字显示太单调,需要用图线显示出来。 战略目标:干掉它。 战术路线:Qt 绘图可以使用 Qt Charts,先了解

    2024年02月11日
    浏览(38)
  • 【VisualStudio】使用 C++ 语言开发 Qt 环境配置教程

    知识不是单独的,一定是成体系的。更多我的个人总结和相关经验可查阅这个专栏:Visual Studio。 先上一张效果图,具体步骤主要分为以下三步。 这一步不再赘述,注意一定要安装 C++ 语言。 可以参考这个教程 Visual Studio 2022安装与使用教程。 这一步也不再赘述,网上搜索教

    2024年02月10日
    浏览(63)
  • QT作业4

    实现一个闹钟,当输入时间后,点击启动到达时间后循环播报三遍,便签内容 头文件: 源文件: 主函数文件: 运行结果: 思维导图:

    2024年02月04日
    浏览(27)
  • QT周五作业

    题目:实现简单水果的价格重量计算 点击一次水果重量+1  自动计算总价 代码: widget.h widget.cpp

    2024年02月02日
    浏览(29)
  • QT周四作业

    题目: 代码: widget.cpp widget.h

    2024年01月21日
    浏览(30)
  • 7.28 作业 QT

    手动完成服务器的实现,并具体程序要注释清楚: widget.h: widget.cpp: 思维导图:    

    2024年02月15日
    浏览(28)
  • 7.10 qt作业

    闹钟

    2024年02月16日
    浏览(26)
  • 7.26 作业 QT

    1.继续完善登录框,当登录成功时,关闭登录界面,跳转到新的界面中: 结果图:  second.h: widget.h: main.cpp: second.cpp: widget.cpp: 2.新建一个工程文件,将默认提供的代码加上注释信息: .pro: 3.思维导图:

    2024年02月15日
    浏览(39)
  • 【VisualStudio】基于 Visual Studio 使用 C++ 语言开发 Qt 环境配置教程

    知识不是单独的,一定是成体系的。更多我的个人总结和相关经验可查阅这个专栏:Visual Studio。 先上一张效果图,具体步骤主要分为以下三步。 这一步不再赘述,注意一定要安装 C++ 语言。 可以参考这个教程 Visual Studio 2022安装与使用教程。 这一步也不再赘述,网上搜索教

    2024年02月15日
    浏览(50)
  • 【Visual Studio】使用 C++ 语言,配合 Qt,开发了一个串口通信界面

    知识不是单独的,一定是成体系的。更多我的个人总结和相关经验可查阅这个专栏:Visual Studio。 我要使用的功能比较简单,主要包含扫描串口、打开串口、发送数据、接收数据、暂停按钮、停止按钮,因此接下里将围绕这几个功能依次更新。 我的工程项目名字叫 “GUI”。

    2024年02月11日
    浏览(57)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包