Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to set QCoreApplication organization name and domain correctly on macOS?



  • QCoreApplication has methods setOrganizationDomain(), setOrganizationName() and setApplicationName().

    If I set the domain as com.myapp and application name as MyApp, my local settings as provided by QStandardPaths::AppDataLocation in macOS are still located at ~\Library\Application Support\MyApp\... instead of ~\Library\Application Support\com.myapp.MyApp\....

    What is the correct way to set them up so QStandardPaths::AppDataLocation would point to macOS-style settings path?


  • Lifetime Qt Champion

    Hi,

    There's nothing wrong with that. Take for example Spotlight, it uses com.apple.spotlight.



  • @SGaist Great so how can I achieve the same path for my app com.myapp.MyApp?



  • Let's clarify a few things.
    For one of my apps, I define this:

    app.setApplicationName(QString("BasicCalc"));
    app.setOrganizationName(QString("mpergand"));
    app.setOrganizationDomain(QString("mpergand.fr"));
    

    After compilation I see this in the Info.plist :

    Bundle name = BasicCalc
    Bundle Identifier = fr.mpergand.BasicCalc
    

    Therefore, the app support path is:

    ~/Library/Application Support/mpergand/Basicalc
    

    The preferences file name (QSettings) is:

    fr.mpergand.BasicCalc.plist
    

    And it is what I expected because it's how it must work on Mac.



  • @mpergand Hey. Thanks for providing an example. All is good with the exception that it's not how it must work on Mac. This is how it may work. In fact apps that run in Sandbox (from AppStore) use different path. And other apps may have path ~/Library/Application Support/fr.mpergand.BasicCalc/ for settings directory. The question was if it is possible to achieve this in Qt with QStandardPaths and proper settings in setApplication Name/Organization/etc.() APIs.



  • @ribtoks said in How to set QCoreApplication organization name and domain correctly on macOS?:

    @mpergand Hey. Thanks for providing an example. All is good with the exception that it's not how it must work on Mac. This is how it may work. In fact apps that run in Sandbox (from AppStore) use different path.

    My bad, I was not aware of this (I'm not using AppleStore)
    Maybe you have to add a specific entry in the info.plist for the sandbox ?



  • @mpergand The thing is that whether in sandbox or not, app learns about appropriate paths available for writing using system calls (like NSLibraryDirectory). I'm only trying to learn if it's possible to achieve this with Qt.


Log in to reply