0903 QT day3

widget.h 

#ifndef WIDGET_H
#define WIDGET_H

#include 
#include
#include
#include
#include
#include


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 *event);
private slots:
    void on_kaishi_clicked();

    void on_tingzhi_clicked();

    void on_timeout_sloat();

private:
    Ui::Widget *ui;

    QTimer *t1;

    int id;

    //定义移动的点
    QPoint movepoint;

    QTextToSpeech speech;

    int speechflag;

    int signalflag=1;
};
#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);

    t1=new QTimer(this);

    connect(t1,&QTimer::timeout,this,&Widget::on_timeout_sloat);

    t1->start(100);
    startTimer(100);
}

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

void Widget::timerEvent(QTimerEvent *)
{
    //1、获取系统时间
    QTime systime =QTime::currentTime();

    QString timetext=systime.toString("hh:mm");

    QString speech_text;
    if(ui->shijian->text()==ui->naozhong->text()&&speechflag==1)
    {
        speechflag=2;
    }
    if(speechflag==2)
    {
        speech_text=(ui->shijian->text())+(ui->beizhu->text());

        speech.say(speech_text);
    }

}

void Widget::on_timeout_sloat()
{
    QTime currenttime=QTime::currentTime();

    QString time =currenttime.toString("hh:mm");

    ui->shijian->setText(time);
}

void Widget::on_kaishi_clicked()
{
    ui->kaishi->setEnabled(false);
    ui->naozhong->setEnabled(false);
    speechflag=1;
}

void Widget::on_tingzhi_clicked()
{
    ui->kaishi->setEnabled(true);
    ui->naozhong->setEnabled(true);
    speechflag=0;
    //ui->beizhu->setText(clean);
}

0903 QT day3_第1张图片 

 

你可能感兴趣的:(qt,ui,开发语言)