当前位置:网站首页>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、选择文件确定 把文件内容展示出来

边栏推荐
- Variables, process control and cursors (MySQL)
- Delete data in SQL
- [tools] basic concept of database and MySQL installation
- .net中 接口可以有默认实现了
- 我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
- Do you know the five most prominent advantages of E-bidding?
- Lavel PHP artisan automatically generates a complete set of model+migrate+controller commands
- 19. (ArcGIS API for JS) ArcGIS API for JS line acquisition (sketchviewmodel)
- input_ delay
- 体会设计细节
猜你喜欢

Mathematical induction and recursion

About Tolerance Intervals

【DPDK】dpdk样例源码解析之三:dpdk-l3fwd_001

什么是 BA ?BA怎么样?BA和BI是什么关系?

leetcode

When you go to the toilet, you can clearly explain the three Scheduling Strategies of scheduled tasks

RestClould ETL 社区版六月精选问答

input_ delay

23. (ArcGIS API for JS) ArcGIS API for JS ellipse collection (sketchviewmodel)

函数重入、函数重载、函数重写自己理解
随机推荐
概率论公式
Leetcode-02 (linked list question)
Jerry's broadcast has built-in flash prompt tone to control playback pause [chapter]
图形化工具打包YOLOv5,生成可执行文件EXE
Open3d mesh filtering
体会设计细节
亚像素级角点检测Opencv-cornerSubPix
函数重入、函数重载、函数重写自己理解
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
CVPR 2022 最佳论文候选 | PIP: 6个惯性传感器实现全身动捕和受力估计
sshd[12282]: fatal: matching cipher is not supported: aes256- [email protected] [preauth]
密码学系列之:在线证书状态协议OCSP详解
Open3D 网格滤波
RestClould ETL 社区版六月精选问答
Matlab Error (Matrix dimensions must agree)
Function reentry, function overloading and function rewriting are understood by yourself
装饰设计企业网站管理系统源码(含手机版源码)
Decoration design enterprise website management system source code (including mobile source code)
[dream database] add the task of automatically collecting statistical information
代码质量管理