一、添加头文件
#include <QFile>
#include <QFileInfo>
#include <QFileDialog>
二、具体操作
void MainWindow::ShowFilePath()
{ui->textEdit->append("请选择文件夹路径...");QString FileDirPath = QFileDialog::getExistingDirectory(this,"请选择文件夹路径...","./");if(FileDirPath.isEmpty()) return;ui->textEdit->append(FileDirPath);QString filefull;QString filename;QString filepath;QString filesuffix ;QFileInfo fileinfo;ui->textEdit->append("请选择文件路径...");file_full = QFileDialog::getOpenFileName(this,"",".",//. 代表程序运行目录 /代表当前盼复的根目录 打开程序运行目录下的Data文件夹作为默认打开路径,这里应该写成"./Data/","Python Files(*.py)",0,0);fileinfo = QFileInfo(file_full);//文件名filename = fileinfo.fileName();//文件后缀filesuffix = fileinfo.suffix();//绝对路径filepath = fileinfo.absolutePath();ui->textEdit->append("文件名...");ui->textEdit->append(file_name);ui->textEdit->append("文件后缀...");ui->textEdit->append(file_suffix);ui->textEdit->append("绝对路径...");ui->textEdit->append(file_path);
}