在qt-creator中debug的时候,发现程序不能读写所在目录的配置文件,资源文件。
原来currentPath位于applicationDirPath上层。
在我的机器上的一个 application output:
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