qt-creator中的 运行程序的 工作目录 与 程序所在的目录
2016-11-26 21:57
323 查看
来源:http://blog.chinaunix.net/uid-26578940-id-3052126.html
在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____"
这种情况下,需要将到用到的文件复制到构建目录才能读写得到。
补充:在程序员的代码里,默认的路径是QDir::currentPath()
在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____"
这种情况下,需要将到用到的文件复制到构建目录才能读写得到。
补充:在程序员的代码里,默认的路径是QDir::currentPath()
相关文章推荐
- Qt之获取运行程序的工作目录与程序所在的目录
- qt运行程序的工作目录
- cmd运行的程序的工作目录
- Qt 程序获取程序所在路径、用户目录路径、临时文件夹等特殊路径的方法
- c#获取当前运行程序所在的目录
- java中取得 当前程序运行所在的目录
- 程序运行时被用户删除了工作目录后崩溃
- Qt 程序获取程序所在路径、用户目录路径、临时文件夹等特殊路径的方法
- 运行的应用程序的当前工作目录和所在的目录的区别
- c#获取当前运行程序所在的目录
- 应用程序所在目录 与 程序工作目录
- 查看运行程序所在目录
- evc 获得程序运行所在的目录
- Qt 程序获取程序所在路径、用户目录路径、临时文件夹等特殊路径的方法
- Qt官方开发环境生成的exe发布方式--使用windeployqt(windeployqt是单独的程序,放在低版本qt4目录下也可以运行的)
- Qt Qprocess 启动新程序切换工作目录
- 运行的应用程序的当前工作目录和所在的目录的区别
- Qt 程序获取程序所在路径、用户目录路径、临时文件夹等特殊路径的方法
- 总结C#中得到程序当前工作目录和执行目录的一些方法
- [转]C#中得到程序当前工作目录和执行目录的一些方法