当前位置:首页 > 编程笔记 > 正文
已解决

华清远见第六课程day10作业

来自网友在路上 173873提问 提问时间:2023-09-20 02:46:42阅读次数: 73

最佳答案 问答题库738位专家为你答疑解惑

保纯

//保存按钮对应的槽函数
void Widget::on_saveBtn_clicked()
{QString fileName = QFileDialog::getSaveFileName(this,              "保存文件",         "./",              "All(*.*);;Images (*.png *.xpm *.jpg);;Text files(*.txt);;XML files(*.xml)");       //过滤器//判断是否选中文件if(fileName.isNull())   {QMessageBox::information(this, "提示", "用户取消了保存文件");return;}qDebug()<<fileName;         //文件操作//1、实例化一个文件对象QFile file(fileName);//2、打开文件if(!file.isOpen())          {//调用打开文件操作if(!file.open(QFile::WriteOnly)){QMessageBox::critical(this, "失败", "文件打开失败");return;           }}//3、读写操作QString msg = ui->textEdit->toPlainText();file.write(msg.toLocal8Bit());//4、关闭文件file.close();QMessageBox::information(this, "提示", "文件保存成功");}

到点播报文本框内容

头文件

  #ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include<QTimerEvent>
#include<QTime>
#include<QPushButton>
#include<QDebug>
#include<QtDebug>
#include<iostream>
#include<QIcon>
#include<QPushButton>
#include<QLineEdit>
#include<QLabel>
#include<QMessageBox>
#include <QTextEdit>
#include<QTextCharFormat>
#include <QTextToSpeech>QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();void timerEvent(QTimerEvent *e)override;
private:Ui::MainWindow *ui;int timer_id;QLabel *systime;QTextEdit *saytext;QLineEdit *settime;QPushButton *start;QPushButton *stop;QTextToSpeech *tts;private slots:void on_startBtn_clicked();void on_closeBtn_clicked();};
#endif // MAINWINDOW_H

源文件

#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);this->setFixedSize(720,460);tts = new QTextToSpeech(this);timer_id=this->startTimer(1000);systime = new QLabel(this);systime->move(60,45);systime->resize(280,80);systime->setStyleSheet("background-color:rgb(222,222,222)");QTime sys_t = QTime::currentTime();QString ti = sys_t.toString("hh:mm:ss");this->systime->setText(ti);QFont font("Microsoft YaHei",20,20);systime->setFont(font);systime->setAlignment(Qt::AlignCenter);settime=new QLineEdit(this);settime->resize(230,40);settime->move(390,45);saytext=new QTextEdit(this);saytext->resize(570,250);saytext->move(systime->x(),systime->y()+130);start=new QPushButton("start",this);start->move(settime->x(),settime->y()+55);start->resize(100,35);connect(start,SIGNAL(clicked()),this,SLOT(on_startBtn_clicked()));stop=new QPushButton("stop",this);stop->move(start->x()+130,start->y());stop->resize(100,35);connect(stop,SIGNAL(clicked()),this,SLOT(on_closeBtn_clicked()));
}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::timerEvent(QTimerEvent *e){if(e->timerId()==timer_id){QTime sys_t = QTime::currentTime();QString ti = sys_t.toString("hh:mm:ss");this->systime->setText(ti);if(ti==settime->text()){tts->say(saytext->toPlainText());}}
}void MainWindow::on_startBtn_clicked()
{timer_id = this->startTimer(1000);}void MainWindow::on_closeBtn_clicked()
{this->killTimer(timer_id);
}

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"华清远见第六课程day10作业":http://eshow365.cn/6-9721-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!