LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C++ preferences (https://www.linuxquestions.org/questions/programming-9/c-preferences-321849/)

rahul_kulkarni 05-09-2005 11:30 PM

C++ preferences
 
Hello All,

In JAVA we have java.util.prefs.Preferences class which allows applications to store and retrieve user and system preferences and configuration data.

Is anything similar to this also available on C++? I want it particularly on linux platform.

Thanks in advance.
// Rahul

devilkin 05-09-2005 11:52 PM

I highly doubt that you will be able to find such an interface in c++ even on a windows machine.

Makes Java sound very nice.

Tinkster 05-10-2005 12:01 AM

Code:

from the Qt documentation
Detailed Description
The QSettings class provides persistent platform-independent application settings.

On Unix systems, QSettings uses text files to store settings.
On Windows systems, QSettings uses the system registry.
On Mac OS X, QSettings uses the Carbon preferences API.

Each setting comprises an identifying key and the data
associated with the key. A key is a unicode string which
consists of two or more subkeys. A subkey is a slash, '/',
followed by one or more unicode characters (excluding
slashes, newlines, carriage returns and equals, '=', signs).
The associated data, called the entry or value, may be
a boolean, an integer, a double, a string or a list of strings.
Entry strings may contain any unicode characters.

If you want to save and restore the entire desktop's settings,
i.e. which applications are running, use QSettings to save
the settings for each individual application and QSessionManager
to save the desktop's session.

That what you're after?


Cheers,
Tink

sasho 05-10-2005 12:27 AM

Re: C++ preferences
 
Quote:

Originally posted by rahul_kulkarni
Hello All,

In JAVA we have java.util.prefs.Preferences class which allows applications to store and retrieve user and system preferences and configuration data.

Is anything similar to this also available on C++? I want it particularly on linux platform.

Thanks in advance.
// Rahul

For constant values is good to have bunch of #define statements in one file, globals.h for example. For saved user configuration you can make a hidden directory in user's home directory and store ihs/her settings there. See how other apps such as Gaim do this.

Harmaa Kettu 05-10-2005 02:00 AM

Quote:

The QSettings class provides persistent platform-independent application settings.
That QT class (probably) does what you want, but QT is a big library and requires even bigger X libraries. Use it only if your application already uses QT for other things. Otherwise, glib configuration file parser is better solution.

Quote:

Makes Java sound very nice.
The idea is nice, but the implementation is not. Java does not let you specify the path and name of the properties file, which makes it impossible to use standard unix/linux names /etc/appname and ~/.appname.

Tinkster 05-10-2005 03:40 AM

Quote:

Originally posted by Harmaa Kettu
[B]That QT class (probably) does what you want, but QT is a big library and requires even bigger X libraries. Use it only if your application already uses QT for other things.
http://www.uwyn.com/projects/tinyq/

Look again ;)


Quote:

Otherwise, glib configuration file parser is better solution.
Which is C, not C++?
Plus you get the rest of gnome libraries which aren't
any leaner than Qt?


Cheers,
Tink

Harmaa Kettu 05-10-2005 04:43 AM

I didn't know about that. Unfortunately it seems to be dead project (last update 2002-10-28, QT version 3.0.6).

Quote:

Which is C, not C++?
What is the problem with that? Libraries written in C can be used in C++ code.

Quote:

Plus you get the rest of gnome libraries which aren't
any leaner than Qt?
Gnome programs and libraries use glib, but glib itself does not require any other libraries, except of course the standard C library.

Tinkster 05-10-2005 04:51 AM

Quote:

Originally posted by Harmaa Kettu
What is the problem with that? Libraries written in C can be used in C++ code.
I just assumed that he wants an OO approach since
he was coming from Java and asking for C++


All times are GMT -5. The time now is 10:23 AM.