当前位置:网站首页>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

边栏推荐
- Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point
- 卡尔曼滤波-1
- Jerry's transmitter crashed after the receiver shut down [chapter]
- API data interface of A-share index component data
- About Confidence Intervals
- PIP download only, not install
- R数据分析:cox模型如何做预测,高分文章复现
- Jerry's ble exiting Bluetooth mode card machine [chapter]
- Flink Task退出流程与Failover机制
- Enumeration general interface & enumeration usage specification
猜你喜欢

注意力机制原理

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

华为小米互“抄作业”

23.(arcgis api for js篇)arcgis api for js椭圆采集(SketchViewModel)

哈夫曼树基本概念
![[security attack and Defense] how much do you know about serialization and deserialization?](/img/1c/e5ae74e65bacf688d7f61cc1b71d3e.png)
[security attack and Defense] how much do you know about serialization and deserialization?

VHDL实现任意大小矩阵加法运算

1200.Minimum Absolute Difference

什么是 BA ?BA怎么样?BA和BI是什么关系?

QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
随机推荐
MySQL的索引
Shell programming basics
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
Probability formula
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
概率论公式
Basic concepts of Huffman tree
我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
体会设计细节
Leetcode-02 (linked list question)
【colmap】已知相机位姿情况下进行三维重建
My brave way to line -- elaborate on what happens when the browser enters the URL
Restcloud ETL Community Edition June featured Q & A
Install torch 0.4.1
Enumeration general interface & enumeration usage specification
Principle of attention mechanism
QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
First understand the principle of network
Lab1 configuration script
25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)