1.获取程序根路径
QString path;
QDir dir;
path=dir.currentPath();
QMessageBox::warning(0,"PATH",path,QMessageBox::Yes);//查看路径
QString path;
QDir dir;
path=dir.currentPath();
//打开资源路径
QFileInfo fi=QFileInfo(path);
QString filePath;
filePath=fi.absolutePath();
QDesktopServices::openUrl(QUrl(filePath, QUrl::TolerantMode));
3.同上方法
//获取程序根目录
QString path;
QDir dir;
path=dir.currentPath();
//打开资源路径
// QFileInfo fi=QFileInfo(path);
// QString filePath;
// filePath=fi.absolutePath();
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(path).absoluteFilePath()));
4.通过打开文件对话框打开文件路径
//获取程序根目录
QString path;
QDir dir;
path=dir.currentPath();
QFileDialog dialog;
if(dialog.exec())
{
QString file = dialog.selectedFiles().at(0);
QFileInfo info(path);
qDebug()<<"path is "<<info.path();
}
5.准确判断文件是否存在
//用QFileInfo::isFile()方法
//准确判断文件夹是否存在1.用QFileInfo::isDir()方法2.用QDir::exists()方法
//不确定字符串是文件还是文件夹路径1.用QFileInfo::exists()方法2.用QFile::exists()方法