Currently Working Directory on Windows vs Mac OS X ...



  • Hello,

    On startup I would like to set my application's working directory to where the application's folder location is.

    So, the following works great on Windows:

    @
    QApplication a(argc, argv);
    QDir::setCurrent(QApplication::applicationDirPath());
    QTPrimaryApplicationWindow w;
    w.setWindowTitle("Ready to Process");
    w.resize(780, 480);
    QMessageBox::information(&w, QObject::tr("Current Directory"),
    QObject::tr("Current working directory is: ") + QApplication::applicationDirPath(), QMessageBox::Ok );
    @

    However, when I run this on a Mac what happens is that the application's working directory is two levels deeper in the "Contents/MacOS" folder.

    I would have to then do:

    @
    QDir::cdUp();
    QDir::cdUp();
    @

    To get where the "application" is alongside all of the other files, etc.

    Is there a better, cross-platform way to do what I want to do or is this the only way?

    Thank you!


Log in to reply