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. Path changing on Mac [solved]
Forum Updated to NodeBB v4.3 + New Features

Path changing on Mac [solved]

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.3k Views 2 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.
  • S Offline
    S Offline
    Saulo Fonseca
    wrote on last edited by Saulo Fonseca
    #1

    Hi there. I am having a strange problem. I build an App in Qt5 that I want to run also in a Mac. The App needs to write a small TXT file. On windows, there is no problem, since it writes on the folder where the executable is. But on the Mac, the current path changes depending on how you run the App:

    • If I double-click the .app file, the current path is / (root) and I get permission denied.

    • If I run from Qt-Creator, the current path is file.app/Contents/Mac. It writes the file inside the App Bundle.

    • If I run the executable inside the bundle from console, like file.app/Contents/Mac/file, the current path is where the file.app is.

    I don't want to define a fixed path when I run QFile::open(). How to make sure that the app always write in the folder where it is?

    Thanks in advance.

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

      Hi,

      Technically what you are trying to do is not clean. If you install your software on Windows (in Program Files), then it will also try to write to a read-only location and will fail. You should rather use QStandardPaths to retrieve one of the known path to store application data. On OS X, writing files in the bundle from your application is also not something that you should do.

      If you still want to do that, QCoreApplication::applicationDirPath is what you are looking for, but again, you should not

      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
      0
      • S Offline
        S Offline
        Saulo Fonseca
        wrote on last edited by
        #3

        Hi SGaist, your suggestion works, Thank you. Despite your advice, I think an App should write all its small configuration files along with its executable. For the case of user data, your are right - it should save the data in a known system wide folder.

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

          Then you are going against Linux, OS X and Windows design guidelines at least.

          Have a look at QStandardPaths::StandardLocation more specifically the ConfigLocation key.

          Also, for application settings your have QSettings that handles the OS specific implementations for you.

          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
          0
          • S Offline
            S Offline
            Saulo Fonseca
            wrote on last edited by Saulo Fonseca
            #5

            You are right. Sorry about it. I didn't know the QSettings class. It seems to be what I need. I will follow your advice. Thank you.

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

              You're welcome !

              Since you have everything you need, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

              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
              0
              • S Offline
                S Offline
                Saulo Fonseca
                wrote on last edited by
                #7

                Done! Thank you one time more.

                1 Reply Last reply
                0

                • Login

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