Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDir get current path not working in release mode on Mac
Qt 6.11 is out! See what's new in the release blog

QDir get current path not working in release mode on Mac

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AmrCoderA Offline
    AmrCoderA Offline
    AmrCoder
    wrote on last edited by
    #1

    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

    CurrentPath/Name_of_the_app/Contents/MacOS/CurrentDate
    

    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

    //CurrentDate
    

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

    1 Reply Last reply
    0
    • Cobra91151C Offline
      Cobra91151C Offline
      Cobra91151
      wrote on last edited by
      #2

      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: http://doc.qt.io/qt-5/qdir.html#mkpath

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved