当前位置:网站首页>QT opens a file and uses QFileDialog to obtain the file name, content, etc
QT opens a file and uses QFileDialog to obtain the file name, content, etc
2022-07-07 03:41:00 【Program yuan ZCC】
Main code :
//.h
#include <QFile>
#include <QFileDialog>
QFile *localFile;
QString filename;
qint64 totalBytes; // Total bytes of file
QByteArray authorizeFile;
//.cpp
// First bind the button to open the file
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;
}
// Get file size
this->totalBytes = localFile->size();
qDebug() << "this->totalBytes====" << this->totalBytes;
// Get everything in the file
authorizeFile = localFile->readAll();
fileTxt = QString(authorizeFile);
ui->textEdit->setText(fileTxt);
}1、 Click the open file button Pop up the select File pop-up box

2、 Pop up and press cancel Tips

3、 Select file to confirm Show the contents of the document

边栏推荐
- First understand the principle of network
- Probability formula
- [dream database] add the task of automatically collecting statistical information
- PHP lightweight Movie Video Search Player source code
- codeforces每日5题(均1700)-第七天
- 【安全攻防】序列化與反序列,你了解多少?
- My brave way to line -- elaborate on what happens when the browser enters the URL
- SSL certificate deployment
- 什么是 BA ?BA怎么样?BA和BI是什么关系?
- 如何自定义Latex停止运行的快捷键
猜你喜欢

QT thread and other 01 concepts

数学归纳与递归

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

Flink Task退出流程与Failover机制

Set static IP for raspberry pie

Function reentry, function overloading and function rewriting are understood by yourself

Restcloud ETL Community Edition June featured Q & A

Flutter3.0了,小程序不止于移动应用跨端运行

Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications

19.(arcgis api for js篇)arcgis api for js线采集(SketchViewModel)
随机推荐
Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point
Ubuntu 20 installation des enregistrements redisjson
Free PHP online decryption tool source code v1.2
24.(arcgis api for js篇)arcgis api for js点修改点编辑(SketchViewModel)
Install torch 0.4.1
[C language] question set of IX
QT 打开文件 使用 QFileDialog 获取文件名称、内容等
LAB1配置脚本
ubuntu20安装redisjson记录
Set WiFi automatic connection for raspberry pie
A 股指数成分数据 API 数据接口
Vernacular high concurrency (2)
RestClould ETL 社区版六月精选问答
变量、流程控制与游标(MySQL)
Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
密码学系列之:在线证书状态协议OCSP详解
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
qt-线程等01概念