在qt-creator中debug的时候,发现程序不能读写所在目录的配置文件,资源文件。
Google了一下,原来 运行程序的 工作目录 与 程序所在的目录是不同的概念。
跑跑这段代码就知道了:
#include <QDebug>
#include <QDir>QString strCurrentApplicationDirPath=QCoreApplication::applicationDirPath();//获取应用的目录qDebug()<<strCurrentApplicationDirPath;QString strCurrentPath=QDir::currentPath();//获取运行程序的工作目录qDebug()<<strCurrentPath;
原来strCurrentPath位于strCurrentApplicationDirPath上层
在我的机器上的一个 application output:
12:15:23: Starting D:\QT5SourceCode\build-Test-Desktop_Qt_5_12_5_MinGW_64_bit-Debug\debug\Test.exe ...
"D:/QT5SourceCode/build-Test-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/debug"
"D:/QT5SourceCode/build-Test-Desktop_Qt_5_12_5_MinGW_64_bit-Debug"