当前位置:网站首页>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
边栏推荐
- SSL certificate deployment
- R data analysis: how to predict Cox model and reproduce high score articles
- Open3d mesh filtering
- Flink Task退出流程与Failover机制
- Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
- MySQL的索引
- 变量、流程控制与游标(MySQL)
- 如何替换模型的骨干网络(backbone)
- Jericho turns on the display icon of the classic Bluetooth hid mobile phone to set the keyboard [chapter]
- R数据分析:cox模型如何做预测,高分文章复现
猜你喜欢
Sub pixel corner detection opencv cornersubpix
我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
1200.Minimum Absolute Difference
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
A 股指数成分数据 API 数据接口
Restcloud ETL Community Edition June featured Q & A
QT thread and other 01 concepts
Jericho is in non Bluetooth mode. Do not jump back to Bluetooth mode when connecting the mobile phone [chapter]
Significance and measures of source code confidentiality
随机推荐
21.(arcgis api for js篇)arcgis api for js矩形采集(SketchViewModel)
Kalman filter-1
【colmap】已知相机位姿情况下进行三维重建
如何自定义Latex停止运行的快捷键
VHDL实现任意大小矩阵乘法运算
pip只下载不安装
Ubuntu20 installation redisjson record
19.(arcgis api for js篇)arcgis api for js线采集(SketchViewModel)
25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
Jerry's FM mode mono or stereo selection setting [chapter]
CMB's written test - quantitative relationship
22.(arcgis api for js篇)arcgis api for js圆采集(SketchViewModel)
MySQL storage engine
LAB1配置脚本
VHDL implementation of arbitrary size matrix multiplication
2022.6.28
浅谈网络安全之文件上传
[untitled]
概率论公式
API data interface of A-share index component data