当前位置:网站首页>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、选择文件确定 把文件内容展示出来
边栏推荐
- Delete data in SQL
- 22.(arcgis api for js篇)arcgis api for js圆采集(SketchViewModel)
- 19. (ArcGIS API for JS) ArcGIS API for JS line acquisition (sketchviewmodel)
- Lavel PHP artisan automatically generates a complete set of model+migrate+controller commands
- 华为小米互“抄作业”
- 23.(arcgis api for js篇)arcgis api for js椭圆采集(SketchViewModel)
- Jerry's phonebook acquisition [chapter]
- leetcode
- Principle of attention mechanism
- 25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
猜你喜欢
随机推荐
Flutter3.0了,小程序不止于移动应用跨端运行
My brave way to line -- elaborate on what happens when the browser enters the URL
23.(arcgis api for js篇)arcgis api for js椭圆采集(SketchViewModel)
[swift] learning notes (I) -- familiar with basic data types, coding styles, tuples, propositions
Under the tide of "going from virtual to real", Baidu AI Cloud is born from real
[C language] question set of IX
装饰设计企业网站管理系统源码(含手机版源码)
Appx代码签名指南
R数据分析:cox模型如何做预测,高分文章复现
SSL证书错误怎么办?浏览器常见SSL证书报错解决办法
20.(arcgis api for js篇)arcgis api for js面采集(SketchViewModel)
Jerry's RTC clock development [chapter]
25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
[cpk-ra6m4 development board environment construction based on RT thread studio]
input_ delay
Codeforces round 264 (Div. 2) C gargari and Bishop [violence]
ubuntu20安裝redisjson記錄
Shell programming basics
【colmap】已知相机位姿情况下进行三维重建