Important: Please read the Qt Code of Conduct -

QDir get current path not working in release mode on Mac

  • Hello,
    this my first time I work with QT on Mac on a virtual box I make a simple app and I want to create a folder in the current path so I use this code

    QDir dir(QDir::currentPath() + "/" + CurrentDate);
        if (!dir.exists()) {
            dir.mkdir(QDir::currentPath() + "/" + CurrentDate);

    i run the app throw QT and i print the full path to the console and i got the path like this


    so now the first problem is the folder not generated beside the app name it generated inside the app itself how can I fix that I tried to remove this part from the string of the full path but it not work

    FullPath = FullPath.remove("Name_of_the_app/Contents/MacOS");

    so it takes the path without inside the app but it not work.
    the second problem is when I run the app without QT it gives me a very strange output the path be like this


    so what I did wrong make this mistake.
    Thanks in advance.

  • Hi! QDir::currentPath() or qApp->applicationDirPath(); will be pointing to the application directory and adding another directory inside of it.

    I think you have to use: QDir::mkpath(const QString &dirPath) function and add your path to the parameter. It will create all necessary dirs in the path.

    The Qt official documentation:

  • Lifetime Qt Champion


    Rather than removing folder, you can you cd to go up to the folder where the app bundle is located..

Log in to reply