Qt之获取运行程序的工作目录与程序所在的目录

在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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值