Qt-相对路径/工程当前路径问题

在Windows下利用Qt读取图片文件显示时,图片读取该相对路径是出现问题,图片没有显示。

最开始以为exe文件所在的目录是当前路径,后面发现并不是这样的,然后用qDebug打印出当前目录

#include <QDir>

qDebug()<< QDir::currentPath();

打印的调试信息如下

"F:/Qt/helloworld/build-helloworld-Desktop_Qt-Debug"

Windows下QT的默认路径是

"build-helloworld-Desktop_Qt-Debug"

而不是

"build-helloworld-Desktop_Qt-Debug/debug"

或者

"build-helloworld-Desktop_Qt-Debug/release"

原文地址:https://www.cnblogs.com/fancyop/p/Qt_CurrentPath.html