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";上一级目录用 ../ 表示。
相关文章推荐
- Qt 编译时遇到 error: [debug/qrc_music.cpp] Error 1
- Qt PropertyAnimation动画残影
- Qt5+opencv程序打包发布
- 专访安晓辉:Qt是最佳的跨平台解决方案
- Qt5解析json文件
- 如何用Qt Designer快速设计产品的高保真原型
- Qt信号和槽
- QT串口模拟-基本界面
- Qt和Qml交互,及多线程
- 嵌入式开发中qt环境的搭建
- 第一个Qt程序
- 在Qt中使用C++代码创建界面
- QT 学习之路
- Ubuntu 下安装 QT 开发环境
- Ubuntu系统使用Qt Designer设计界面
- Qt的下载和安装
- Qt发展历史及其特点简介
- Qt标准对话框之QMessageBox
- 在VS2013中配置QT5 win7_64
- Qt静态库下载与安装说明