当前位置:网站首页>QT 打开文件 使用 QFileDialog 获取文件名称、内容等
QT 打开文件 使用 QFileDialog 获取文件名称、内容等
2022-07-06 20:28:00 【程序媛zcc】
主要代码:
//.h
#include <QFile>
#include <QFileDialog>
QFile *localFile;
QString filename;
qint64 totalBytes; //文件总字节数
QByteArray authorizeFile;
//.cpp
//先给按钮绑定打开文件
connect(this->ui->pushButton_openFile, SIGNAL(clicked()), this, SLOT(selectFile()));
void MyDialog::selectFile()
{
this->filename = QFileDialog::getOpenFileName(this, "Open a file", "/", "files (*)");
// ui->textEdit->setText(filename);
this->localFile = new QFile(filename);
if (!localFile->open(QFile::ReadOnly | QIODevice::Text))
{
ui->textEdit->setText(tr("FileSetDialog:open file error!"));
return;
}
// 获取文件大小
this->totalBytes = localFile->size();
qDebug() << "this->totalBytes====" << this->totalBytes;
//获取文件里所有内容
authorizeFile = localFile->readAll();
fileTxt = QString(authorizeFile);
ui->textEdit->setText(fileTxt);
}
1、点击打开文件按钮 弹出选择文件弹框
2、弹框按取消 提示
3、选择文件确定 把文件内容展示出来
边栏推荐
- SSL certificate deployment
- 校招行测笔试-数量关系
- 体会设计细节
- Create applet from 0
- 22.(arcgis api for js篇)arcgis api for js圆采集(SketchViewModel)
- 我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
- Sorting operation partition, argpartition, sort, argsort in numpy
- sshd[12282]: fatal: matching cipher is not supported: aes256- [email protected] [preauth]
- 线性表的查找
- CVPR 2022 最佳论文候选 | PIP: 6个惯性传感器实现全身动捕和受力估计
猜你喜欢
23.(arcgis api for js篇)arcgis api for js椭圆采集(SketchViewModel)
leetcode
About Confidence Intervals
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
VHDL implementation of single cycle CPU design
ubuntu20安裝redisjson記錄
数学归纳与递归
Appx代码签名指南
树莓派设置静态ip
枚举通用接口&枚举使用规范
随机推荐
VHDL implementation of single cycle CPU design
About Tolerance Intervals
24. (ArcGIS API for JS) ArcGIS API for JS point modification point editing (sketchviewmodel)
变量、流程控制与游标(MySQL)
Make (convert) ICO Icon
Flutter3.0, the applet is not only run across mobile applications
ubuntu20安裝redisjson記錄
22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
Jerry's phonebook acquisition [chapter]
MySQL的索引
20. (ArcGIS API for JS) ArcGIS API for JS surface collection (sketchviewmodel)
Opencv environment, and open a local PC camera.
源代码保密的意义和措施
R数据分析:cox模型如何做预测,高分文章复现
How to replace the backbone of the model
unrecognized selector sent to instance 0x10b34e810
Huawei and Xiaomi "copy each other"
装饰设计企业网站管理系统源码(含手机版源码)
Domcontentloaded and window onload
23.(arcgis api for js篇)arcgis api for js椭圆采集(SketchViewModel)