您的位置:首页 > 编程语言 > Qt开发

Qt路径问题

2016-05-09 10:24 471 查看
1.获取应用程序可执行文件所在的目录
QString applicationDirPath;
applicationDirPath = QCoreApplication::applicationDirPath();
qDebug()<<"applicationDirPath"<<applicationDirPath;
2.获取应用程序可执行文件的文件路径
QString applicationFilePath;
applicationFilePath = QCoreApplication::applicationFilePath();
qDebug()<<"applicationFilePath"<<applicationFilePath;
3.获取应用程序当前工作目录的绝对路径
QString currentPath;
QDir dir;
currentPath=dir.currentPath();
qDebug()<<"path"<<currentPath;
上面获取的结果与C++里面下面这段代码同效;
注意,需要#include <direct.h>
char *buffer;
if((buffer = getcwd(NULL, 0)) == NULL)
{
perror("getcwd error");
}
else
{
printf("%s\n", buffer);
free(buffer);
}
运行结果示例当前路径可以用  ./  表示。
QString filePath = "./log/my.log";
上面这种表达方式与下面等效:
QString currentPath;
QDir dir;
currentPath=dir.currentPath();
QString filePath = current_dir+"/log/my.log";
上一级目录用  ../  表示。
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: