I am working on a desktop GUI application that should run natively on Windows, Mac OS X, and Linux. What is the preferred way to save preferences in a cross-platform application? I am using C ++, but the question (and its answers) must be valid for any originally compiled language. (Solutions for dynamic languages and Java can be seen here .)
My research so far tells me that there are at least two strategies:
(A) Use OS-specific API settings functions.
(B) Save the settings in a file in the appropriate (specific OS) folder.
Consider method (A): I believe that this NSUserDefaultsis the correct method for Mac OS X. On Windows systems, I write to the registry through RegOpenKeyEx. But some questions arise: is there a comparable and portable Linux API for this? Is a Windows registry entry a really reliable solution?
To keep things simple, I tend to follow method (B). Thus, I just have OS-specific code to get the appropriate directory where I can store my data in the format I selected. On Windows, I found out SHGetFolderPath(or SHGetKnownFolderPathfor the latest Windows systems) and that CSIDL_LOCAL_APPDATAis the way to go. On Mac computers, an NSSearchPathForDirectoriesInDomainsAPI call should do the same; it is an Objective-C API, although it complicates the situation. Finally, for a version of Linux using getenv("HOME")(and getpwuid()as a fallback solution) is recommended.
:
1. - , ?
2. - ++, , , ? ( QSetting, FLTK, GUI.)
:
"" , , . , ..