Qt之获取运行程序的工作目录与程序所在的目录
2016-08-23 15:12
447 查看
在qt-creator中debug的时候,发现程序不能读写所在目录的配置文件,资源文件。
Google了一下,原来 运行程序的 工作目录 与 程序所在的目录是不同的概念。
跑跑这段代码就知道了:
qDebug()<<"current applicationDirPath: "<<QCoreApplication::applicationDirPath();
qDebug()<<"current currentPath: "<<QDir::currentPath();
原来currentPath位于applicationDirPath上层。
在我的机器上的一个 application output:
Starting D:\jianixrabbit\develop\get_current_dir-build-desktop-Qt_4_8_0__Qt____\debug\llll.exe...
current applicationDirPath: "D:/jianixrabbit/develop/get_current_dir-build-desktop-Qt_4_8_0__Qt____/debug"
current currentPath: "D:/jianixrabbit/develop/get_current_dir-build-desktop-Qt_4_8_0__Qt____"这种情况下,需要将到用到的文件复制到构建目录才能读写得到。
原网址:http://blog.chinaunix.net/uid-26578940-id-3052126.html
Google了一下,原来 运行程序的 工作目录 与 程序所在的目录是不同的概念。
跑跑这段代码就知道了:
qDebug()<<"current applicationDirPath: "<<QCoreApplication::applicationDirPath();
qDebug()<<"current currentPath: "<<QDir::currentPath();
原来currentPath位于applicationDirPath上层。
在我的机器上的一个 application output:
Starting D:\jianixrabbit\develop\get_current_dir-build-desktop-Qt_4_8_0__Qt____\debug\llll.exe...
current applicationDirPath: "D:/jianixrabbit/develop/get_current_dir-build-desktop-Qt_4_8_0__Qt____/debug"
current currentPath: "D:/jianixrabbit/develop/get_current_dir-build-desktop-Qt_4_8_0__Qt____"这种情况下,需要将到用到的文件复制到构建目录才能读写得到。
原网址:http://blog.chinaunix.net/uid-26578940-id-3052126.html
相关文章推荐
- qt-creator中的 运行程序的 工作目录 与 程序所在的目录
- Qt 程序获取程序所在路径、用户目录路径、临时文件夹等特殊路径的方法
- Qt 程序获取程序所在路径、用户目录路径、临时文件夹等特殊路径的方法
- qt运行程序的工作目录
- Qt 程序获取程序所在路径、用户目录路径、临时文件夹等特殊路径的方法
- Qt 程序获取程序所在路径、用户目录路径、临时文件夹等特殊路径的方法
- c#获取当前运行程序所在的目录
- c#获取当前运行程序所在的目录
- WINCE.NET4.2下如何获取程序当前运行目录
- c# winform 获取当前程序运行根目录
- 获取本程序的运行目录
- win7中以管理员身份运行bat脚本时,获取当前文件所在目录
- C# 获取运行程序所在路径的几种方法比较
- 获取当前程序所在路径/目录
- 获取Java程序所在目录的简单方法---FYI
- Python获取程序所在目录
- 获取当前程序所在路径/目录
- 获取程序所在目录
- .Net compact Framework 获取程序的运行目录
- 怎样获取程序运行的当前目录