当前位置:网站首页>仿记事本;QFile
仿记事本;QFile
2022-08-08 05:27:00 【Lee Neo】

widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include "filedialog.h"
#include <QFile>
#include <QDateTime>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_pushButton_clicked()
{
//创建文件;
QFile file;
file.setFileName(QDateTime::currentDateTime().toString("MMddhhmmss")+".txt");
file.open(QIODevice::ReadWrite);
FileDialog filedialog;
filedialog.resize(this->size());//设置窗口大小
filedialog.show();
filedialog.setModal(true);//不能点击父界面
filedialog.exec();//让界面一直存在;
//写入文件内容;
file.write(filedialog.getTextEditContent().toUtf8());
file.close();
//判断有没有内容;
if(filedialog.getTextEditContent().length() == 0)
file.remove();
}
filedialog.cpp
#include "filedialog.h"
#include "ui_filedialog.h"
FileDialog::FileDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::FileDialog)
{
ui->setupUi(this);
this->setLayout(ui->verticalLayout);
}
FileDialog::~FileDialog()
{
delete ui;
}
QString FileDialog::getTextEditContent()
{
return ui->textEdit->toPlainText();
}
void FileDialog::on_pushButton_clicked()
{
this->close();//关闭窗口;
}
边栏推荐
猜你喜欢

Hundreds of billions, large-scale: performance tuning practice of Tencent's super-large Apache Pulsar cluster

浅学软件逆向笔记(1)

Use of Filter

121道分布式面试题和答案

由联合体union引出的大小端问题

【OAuth2】十八、OIDC的认识应用

Web attack log analysis: a guide for beginners

Unity-CharacterController (Character Controller)

为什么互联网大厂一边疯狂裁员,一边不停招聘?

Leetcode78. Subset
随机推荐
TSF微服务治理实战系列(二)——服务路由
Leetcode sword 】 refers to the Offer (special commando) summary
cs软件ui构建办法
Unity-CharacterController (Character Controller)
使用 Zap 和 W3af 进行 Web 应用程序漏洞评估
数据库系统原理与应用教程(080)—— MySQL 练习题:操作题 186-193(二十四):综合练习
C language force to deduct the length of the last word of the 58th question.Traverse from back to front
KDD‘22推荐系统论文梳理(24篇研究&36篇应用论文)
Sqlmap + dnslog injection of repetition
Mail online cobalstrike fishing
Leetcode78. Subset
Unity-CharacterController(角色控制器)
为什么互联网大厂一边疯狂裁员,一边不停招聘?
硬盘基础知识
LVS:NAT模式详解
sessionStorage在不同页签中的数据是否共享问题及解决思路
Rust开发——Struct使用示例
C language framework FreeSwitch custom event introduction and usage example
Typescript 命名空间
The difference between classification, object detection, semantic segmentation, and instance segmentation