当前位置:网站首页>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
边栏推荐
- 未来发展路线确认!数字经济、数字化转型、数据...这次会议很重要
- QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
- Clock in during winter vacation
- [dream database] add the task of automatically collecting statistical information
- Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point
- Open3D 网格滤波
- [leetcode] 450 and 98 (deletion and verification of binary search tree)
- Jerry's phonebook acquisition [chapter]
- 如何自定义Latex停止运行的快捷键
- Flutter3.0, the applet is not only run across mobile applications
猜你喜欢
How to replace the backbone of the model
20.(arcgis api for js篇)arcgis api for js面采集(SketchViewModel)
Decoration design enterprise website management system source code (including mobile source code)
20. (ArcGIS API for JS) ArcGIS API for JS surface collection (sketchviewmodel)
Que savez - vous de la sérialisation et de l'anti - séquence?
[leetcode] 700 and 701 (search and insert of binary search tree)
About Confidence Intervals
Significance and measures of source code confidentiality
枚举通用接口&枚举使用规范
VHDL implementation of arbitrary size matrix multiplication
随机推荐
VHDL实现单周期CPU设计
【安全攻防】序列化与反序列,你了解多少?
About Confidence Intervals
How to replace the backbone of the model
Free PHP online decryption tool source code v1.2
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
PIP download only, not install
22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
源代码保密的意义和措施
Sorting operation partition, argpartition, sort, argsort in numpy
自适应非欧表征广告检索系统AMCAD
Enumeration general interface & enumeration usage specification
浅谈网络安全之文件上传
A 股指数成分数据 API 数据接口
Open3d mesh filtering
VHDL实现任意大小矩阵加法运算
卡尔曼滤波-1
【达梦数据库】备份恢复后要执行两个sql语句
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)