简介
使用 QFileDialog::getOpenFileName 弹出选择文件窗口,
选中文件只会返回文件路径,如果要加直接打开,可以使用下面方法。
思路
QString filePath = QFileDialog::getOpenFileName(this,
"导出excel目录",
"C:\\Users\\18584\\Desktop\\qtcode",//默认打开目录+文件
"excel(*.xls)");//文件类型过滤
if(filePath.isEmpty()){
QMessageBox::warning(this, "提示", "文件路径错误。");
return;
}else
{
//使用 QDesktopServices::openUrl 函数
QDesktopServices::openUrl(QUrl::fromLocalFile(filePath)); //需要添加头文件<QDesktopServices>
}