#include "qtwidgetsapplication4.h"
#include <QFileDialog>
#include <QTextCodec>
#include <QDebug>
#include <QDateTime>
QtWidgetsApplication4::QtWidgetsApplication4(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
connect(ui.pushButton, &QPushButton::clicked, [=]()
{
// 文件弹窗 QFileDialog::getOpenFileName
QString filename =QFileDialog::getOpenFileName(this, "open file", "C:\\Users\\wangxd-m\\Documents\\WXWork\\1688856407349103\\Cache\\File\\2022-08");
ui.lineEdit->setText(filename);
QTextCodec *codec = QTextCodec::codecForName("gbk");
// 文件操作类
QFile file(filename);
file.open(QIODevice::ReadOnly);
QByteArray arr = file.readAll();
ui.textEdit->setText(codec->toUnicode(arr));
file.close();
file.open(QIODevice::Append);
file.write("aaa");
file.close();
// 文件信息类
QFileInfo fileInfo(filename);
qDebug() << fileInfo.fileName() << " \n"
<< fileInfo.created().toString("yyyy/MM/dd hh:mm:ss") << " \n"
<< fileInfo.lastModified().toString("yyyy/MM/dd hh:mm:ss") << " \n"
<< fileInfo.filePath() << " \n"
<< fileInfo.suffix() << " \n"
<< fileInfo.size() << " \n";
});
}
Qt 文件操作
最新推荐文章于 2024-08-29 00:09:28 发布