how to use QSetting with Mac App Groups
-
Hi,
how would I go about saving user settings on mac group container with QSetting?
reading the documentation it seems like QSetting only save the file in one of these location:
- $HOME/Library/Preferences/com.MySoft.Star Runner.plist
- $HOME/Library/Preferences/com.MySoft.plist
- /Library/Preferences/com.MySoft.Star Runner.plist
- /Library/Preferences/com.MySoft.plist
for a sandboxed app, it would be something like:
~/Library/Containers/com.MySoft.Star Runner/Data/Library/Preferences/com.MySoft.Star Runner.plistbut for app group, it should be something like:
~/Library/Group Containers/(teamID).com.MySoft.Star Runner/Library/Preferences/com.MySoft.Star Runner.plistis it possible for QSetting to save user settings in the group container ?
more on mac app group: https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/AddingCapabilities/AddingCapabilities.html#//apple_ref/doc/uid/TP40012582-CH26-SW61
-
Hi and welcome to devnet,
From a quick read through the related documentation, I don't see anything related to the App Groups stating that the application settings should reside there.
On the contrary, it seems to be for sharing data (which settings are not) and/or inter process communication.After a second read, the documentation isn't the most clear about the handling of application settings. You can share settings for apps in a group using NSUserDefaults and thats the goal of the OP which is not the same as storing application specific settings.
[Edit: fixed information]
-
@SGaist thanks for the response,
my situation is that I have 2 apps that I'd like to share some user defaults settings.
in a native Mac app with Swift, we could easily achieve this by using:let sharedUserDefaults = UserDefaults(suiteName: "groupId.com.appGroupName")
which will automatically create/load plist files located under:
~/Library/Group Containers/groupId.com.appGroupName/Library/Preferences/groupId.com.appGroupName.plistis there any alternative that does this with Qt?
-
Looking at the docs, i found:
enum QSettings::Scope This enum specifies whether settings are user-specific or shared by all users of the same system. QSettings::UserScope 0 Store settings in a location specific to the current user (e.g., in the user's home directory). QSettings::SystemScope 1 Store settings in a global location, so that all users on the same machine access the same set of settings.
Not tested ...
-
@gietal said in how to use QSetting with Mac App Groups:
UserDefaults
Thanks of the information. I somehow missed that one.
After a quick verification in QSettings sources, I haven't seen anything specific for the App Group use case.
However, what you can do is use Objective-C++ through NSUserDefaults and it init::suiteName method. Then you can use that class to manage your shared settings.