qt-creator中的 运行程序的 工作目录 与 程序所在的目录

来源:互联网 发布:云顶娱乐软件下载 编辑:程序博客网 时间:2024/05/23 01:15

来源:http://blog.chinaunix.net/uid-26578940-id-3052126.html

在qt-creator中debug的时候,发现程序不能读写所在目录的配置文件,资源文件。
Google了一下,原来 运行程序的 工作目录 与 程序所在的目录是不同的概念。

跑跑这段代码就知道了:
  1. qDebug()<<"current applicationDirPath: "<<QCoreApplication::applicationDirPath();
  1. qDebug()<<"current currentPath: "<<QDir::currentPath();

原来currentPath位于applicationDirPath上层。
在我的机器上的一个 application output:

  1. Starting D:\jianixrabbit\develop\get_current_dir-build-desktop-Qt_4_8_0__Qt____\debug\llll.exe...
  2. current applicationDirPath: "D:/jianixrabbit/develop/get_current_dir-build-desktop-Qt_4_8_0__Qt____/debug"
  3. current currentPath: "D:/jianixrabbit/develop/get_current_dir-build-desktop-Qt_4_8_0__Qt____"

这种情况下,需要将到用到的文件复制到构建目录才能读写得到。

补充:在程序员的代码里,默认的路径是QDir::currentPath()

0 0
原创粉丝点击