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

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: