当前位置:网站首页>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、选择文件确定 把文件内容展示出来

边栏推荐
- Mathematical induction and recursion
- VHDL实现任意大小矩阵加法运算
- 编译常量、ClassLoader类、系统类加载器深度探析
- 【达梦数据库】添加自动收集统计信息的任务
- leetcode
- A 股指数成分数据 API 数据接口
- Jericho turns on the display icon of the classic Bluetooth hid mobile phone to set the keyboard [chapter]
- HDU 4337 King Arthur&#39; S Knights it outputs a Hamiltonian circuit
- [swift] learning notes (I) -- familiar with basic data types, coding styles, tuples, propositions
- [untitled]
猜你喜欢

华为小米互“抄作业”

体会设计细节

ubuntu20安装redisjson记录

VHDL implementation of single cycle CPU design

如何替换模型的骨干网络(backbone)

CVPR 2022 最佳论文候选 | PIP: 6个惯性传感器实现全身动捕和受力估计
![Jericho turns on the display icon of the classic Bluetooth hid mobile phone to set the keyboard [chapter]](/img/f4/8464bf9b66a1215265ac873f286688.png)
Jericho turns on the display icon of the classic Bluetooth hid mobile phone to set the keyboard [chapter]

Huawei and Xiaomi "copy each other"

HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅

Experience design details
随机推荐
哈夫曼树基本概念
Netperf and network performance measurement
When you go to the toilet, you can clearly explain the three Scheduling Strategies of scheduled tasks
Enumeration general interface & enumeration usage specification
Open3D 网格滤波
Ubuntu 20 installation des enregistrements redisjson
[untitled]
Jerry's ble exiting Bluetooth mode card machine [chapter]
25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
Room rate system - login optimization
[Dameng database] after backup and recovery, two SQL statements should be executed
VHDL实现任意大小矩阵加法运算
About Tolerance Intervals
Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point
[leetcode] 450 and 98 (deletion and verification of binary search tree)
我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
Lost in the lock world of MySQL
input_ delay
Create applet from 0
Basic concepts of Huffman tree