Important: Please read the Qt Code of Conduct -

QDir::currentPath() OSX 10.9 Mavericks bug

  • We're noticing that QDir::currentPath() returns nothing in our Qt 4 based application on the latest OSX 10.9 Mavericks operating system. As opposed to returning the location of the folder the application resides in like it used to in previous versions of the mac os. Any suggestions for a work around to fix this issue?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should have a look at the "bug report system": to see whether it's something known. If not you could consider opening a new bug report with as much information as possible.

  • I submitted a bug report.
    Qt QTBUG-34300

    I also discovered a work around while still staying with using Qt calls.

    QApplication::applicationDirPath() appears to work properly on OSX 10.9 Mavericks. So using that and QDir cdUp() 3 times will get you the application folder, since it returns the executable location inside of the mac app bundle.

    So maybe QDir::currentPath should be coded to work that way?

  • While run my app through double-click it
    currentpath() will return /, which is my computer's root folder

    While run my app through Qt Creator
    currentpath() will return the path which I set in the "working directory"

    So, I don't think it's totally qt's fault, maybe 10.9 has changed the way they "execute" our app?

  • Hi Johnd, you should know that the current work directory(CWD) has nothing to do with the directory where the application located in. And you can not get one from the other.

    However, if QDir::currentPath() returns nothing, it should be a bug. As it should return the absolute path of the application's current work directory.

  • I'm having the same problem. QDir::currentPath() does not work on Mac OS X 10.9 (when the app is executed double clicking on it)

  • Moderators


    [quote author="kalos" date="1383045485"]I'm having the same problem. QDir::currentPath() does not work on Mac OS X 10.9 (when the app is executed double clicking on it)[/quote]Like 1+1=2 said, QDir::currentPath() does NOT return the app's directory. It returns the working directory. The working directory can be your app's directory, but they are not the same thing. (Every time you call cd, you change your working directory).

    In Mavericks, Apple changed the way that working directories are set.

    If you want your app's directory, use QCoreApplication::applicationDirPath() instead.

  • As for all OSX application, QDir::currentPath() return the directory of the Unix file inside the application bundle: Your_app/Contents/MacOSX.
    @QDir dir = QDir::currentPath();
    qDebug() << dir.dirName();@

    print "MacOSX". Works on 10.9 as on 10.8.

    For the directory of your application (, you need to do:
    @QDir dir = QDir::currentPath();

    and you can print the full path with
    @qDebug() << dir.absolutePath(); @

Log in to reply