当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
编译常量、ClassLoader类、系统类加载器深度探析
Jerry's ble exiting Bluetooth mode card machine [chapter]
2022年上半年HIT行业TOP50
My brave way to line -- elaborate on what happens when the browser enters the URL
树莓派设置静态ip
Huawei and Xiaomi "copy each other"
Set WiFi automatic connection for raspberry pie
密码学系列之:在线证书状态协议OCSP详解
如何替换模型的骨干网络(backbone)
存储过程与函数(MySQL)
25.(arcgis api for js篇)arcgis api for js线修改线编辑(SketchViewModel)
2022.6.28
Jerry's transmitter crashed after the receiver shut down [chapter]
卡尔曼滤波-1
自适应非欧表征广告检索系统AMCAD
腾讯云原生数据库TDSQL-C入选信通院《云原生产品目录》
【达梦数据库】备份恢复后要执行两个sql语句
.net中 接口可以有默认实现了
CVPR 2022 best paper candidate | pip: six inertial sensors realize whole body dynamic capture and force estimation
About Confidence Intervals