Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Maemo: Using GConf

From Wiki
Jump to: navigation, search
Article Metadata
Created: nullvoid (04 Jul 2008)
Last edited: hamishwillee (27 Jul 2012)



GConf is a configuration data storage system providing a simple interface to GNOME applications. the aim of the GConf library is to provide a consistent method for applications to access configuration settings as well as to provide tools for administrators to distribute software settings in a centralized manner.

The GConf database may consist of multiple databases, configured by the system admin. Typically at least one database engine uses XML to store the settings. This keeps the database still in a very human-readable form (compared to binary databases). However, client-side interface is always the same, irrespective of the database backend.

One of the features of GConf is the capability of notifying its clients about their settings being changed. This allows the client to react to changes originating from another process in (almost) real-time.

GConf consist of client library and the GConf server daemon. In Maemo, client-server communications is done using D-Bus.

Each application will specify its own directory under /apps/Maemo/application_name/ (in GConf's namespace).

The following data types are supported in GConf:

* gint
* gchar [ASCII/ISO 8859-1/UTF-8]
* gboolean
* gfloat (with limited precision)
* pair of values (useful for key-value pairs)
* list of values of same type

Note that storing binary data is not supported by GConf.

SDK includes a tool gconftool-2 for setting/unsetting keys and displaying contents of keys stored in GConf:

Setting an integer key:

 [sbox-CHINOOK_X86: ~] > gconftool-2 --set \
  /apps/Maemo/myapp/mykey --type=int 42

Unsetting a key:

 [sbox-CHINOOK_X86: ~] > gconftool-2 --unset /apps/Maemo/myapp/mykey

Listing all keys under /apps:

 [sbox-CHINOOK_X86: ~] > gconftool-2 -R /apps

Sample code

  #include <gconf/gconf-client.h>
#define APPLICATION_NAME "myapp"
#define GCONF_DIR "/apps/Maemo/" APPLICATION_NAME "/"
* Store an integer key "mykey" with a specified value to gconf database

static void StoreMykey( gint value ) {
GConfClient* gconfClient = gconf_client_get_default();
if(!gconf_client_set_int(gconfClient, GCONF_DIR "mykey", value, NULL)) {
g_warning(" failed to set %smykey (%d)\n", GCONF_DIR, value);
/* release GConf client */
* Get an integer value from key "mykey"

static void GetMykey( gint* value ) {
GConfClient* gconfClient = gconf_client_get_default();
GConfValue* gcValue = NULL;
gcValue = gconf_client_get_without_default(GConfClient, "mykey", NULL);
/* if value pointer remains NULL, the key was not found */
if(gcValue == NULL) {
g_warning(" key %smykey not found\n", GCONF_DIR);
/* Check if value type is integer */
if(gcValue->type == GCONF_VALUE_INT) {
*value = gconf_value_get_int(gcValue);
else {
g_warning(" key %smykey is not integer\n", GCONF_DIR);
/* Release resources */

Qt wrappers for GConf

Qt developers should use libgq-gconf. This library contains a class called GConfItem, which is a simple C++ wrapper for GConf. Creating a GConfItem instance gives you access to a single GConf key. You can get and set its value and be notified about changes. More information about this class are available at

// Create a new GConfItem object
GConfItem *boolItem = new GConfItem("/gconf/path/to/myBool");
// Read value
qDebug() << "Value is" << boolItem->value().toBool();
// Listening for changes
QObject::connect(boolItem, SIGNAL(valueChanged()), signalSpy, SLOT(valueChanged()));
// Set a value
//Get the key
qDebug() << boolItem->key(); ///gconf/path/to/myBool

See also

This page was last modified on 27 July 2012, at 05:27.
27 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.