当前位置:网站首页>QT学习日记16——QFile文件读写
QT学习日记16——QFile文件读写
2022-07-16 06:19:00 【herb.dr】
目录
一、项目搭建

二、实现读取功能
2.1 读取选取的路径

2.2 读取到文本框中
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
// 点击选取文件按钮,弹出文件对话框
connect(ui->pushButton, &QPushButton::clicked, [=]{
QString path = QFileDialog::getOpenFileName(this, "打开文件", "D:/");
// 将路径放入到lineEdit中
ui->lineEdit->setText(path);
// 读取内容 放入到textEdt中
QFile file(path); // 参数就是苏区文件的路径
// 设置打开方式
file.open(QIODevice::ReadOnly);
QByteArray array = file.readAll();
// 将读取到的数据 放入到textEdt中
ui->textEdit->setText(array);
});
}
2.3 读取格式
QFile 默认读取的格式是 utf8,现在设置用 gbk 格式读取

2.4 按行读

追加着读

2.5 关闭文件
file.close();
三、进行写文件


四、QFileInfo 文件信息读取
4.1 API

4.2 打印文件信息
包含头文件 #include <QFileInfo>

文件路径 filePath();
4.3 日期类型的处理
1、加上头文件 #include <QDateTime>

2、查询 API

3、指定格式输出

最后的修改日期是 lastModified()
边栏推荐
- sudo 找不到命令 command not found 解决方案
- Redis报错MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist...
- Design of intelligent speech recognition Bluetooth headset based on wtk6900h speech recognition single chip
- 网络安全实验:防火墙技术
- 小程序毕设作品之微信评选投票小程序毕业设计(6)开题答辩PPT
- 用swift5 新写一个app需要用到需要考虑的
- 4. Redis architecture design to use scenarios - string, list, set, Zset, hash use scenarios
- Will the arrears of Alibaba cloud international ECS be automatically released?
- IDEA集成Gerrit插件
- STM32 USB虚拟串口通信
猜你喜欢

小程序毕设作品之微信评选投票小程序毕业设计(8)毕业设计论文模板

Network security experiment: firewall technology

Conditional ternary operator...

我为 TDengine “带盐”!“高价”招募出镜开发者

STM32应用开发实践教程:基于 RS-485 总线的多机通信应用开发

启动失败 Failed to determine a suitable driver class 问题解决方案

Design of hydrogen monitoring system based on single chip microcomputer (0491)

Design of intelligent speech recognition Bluetooth headset based on wtk6900h speech recognition single chip

ViewGroup事件分发梳理

小程序毕设作品之微信评选投票小程序毕业设计(6)开题答辩PPT
随机推荐
2022年G2电站锅炉司炉考试试题模拟考试平台操作
angr原理与实践(一)——原理
QT custom control -- pagenavigation
Wechat selection and voting of finished works of applet graduation project (7) mid term inspection report
Why should e-commerce platforms focus on the crime of illegal operation? What is the connection between this and Erqing?
Network security experiment: firewall technology
Total sequencing problem
[每周一更]-(第3期):Web开发安全注意事项
Gee (6): set the number of decimal places reserved for the calculated value / image
What if win11 prompts outlook for search errors? Win11 prompt outlook search error
STM32应用开发实践教程:具备交互功能的人机界面应用开发
Design of hydrogen monitoring system based on single chip microcomputer (0491)
Conditional ternary operator...
Wechat Evaluation of applet design works Voting applet Graduation Design (5) Task Book
保研机试备考十四:BFS
降级机制设计不当,线上系统瞬间崩溃...
4-redis architecture design to usage scenario - redis request execution process
Pointer constant and constant pointer
GEE(6):设置计算数值/影像保留小数位数
微机原理与技术接口 实验三 循环结构