当前位置:网站首页>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
边栏推荐
- Jerry's transmitter crashed after the receiver shut down [chapter]
- 20. (ArcGIS API for JS) ArcGIS API for JS surface collection (sketchviewmodel)
- 卡尔曼滤波-1
- 如何自定义Latex停止运行的快捷键
- Can the applet run in its own app and realize live broadcast and connection?
- 存储过程与函数(MySQL)
- 树莓派设置静态ip
- What about SSL certificate errors? Solutions to common SSL certificate errors in browsers
- [untitled]
- LAB1配置脚本
猜你喜欢
Flink Task退出流程与Failover机制
23.(arcgis api for js篇)arcgis api for js椭圆采集(SketchViewModel)
My brave way to line -- elaborate on what happens when the browser enters the URL
About Tolerance Intervals
太方便了,钉钉上就可完成代码发布审批啦!
预处理——插值
VHDL implementation of arbitrary size matrix multiplication
Enumeration general interface & enumeration usage specification
Jericho is in non Bluetooth mode. Do not jump back to Bluetooth mode when connecting the mobile phone [chapter]
21.(arcgis api for js篇)arcgis api for js矩形采集(SketchViewModel)
随机推荐
Variables, process control and cursors (MySQL)
Function reentry, function overloading and function rewriting are understood by yourself
太方便了,钉钉上就可完成代码发布审批啦!
pip只下载不安装
2022年上半年HIT行业TOP50
校招行测笔试-数量关系
Flink Task退出流程与Failover机制
ubuntu20安裝redisjson記錄
【C语言】 题集 of Ⅸ
Vernacular high concurrency (2)
API data interface of A-share index component data
Shangsilicon Valley JVM Chapter 1 class loading subsystem
浅谈网络安全之文件上传
R data analysis: how to predict Cox model and reproduce high score articles
Depth analysis of compilation constants, classloader classes, and system class loaders
Sorting operation partition, argpartition, sort, argsort in numpy
数学归纳与递归
自适应非欧表征广告检索系统AMCAD
Create applet from 0
23.(arcgis api for js篇)arcgis api for js椭圆采集(SketchViewModel)