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.

Using GConf from QML applications

From Wiki
Jump to: navigation, search

This article explains how to use GConf from QML applications.

Article Metadata
Tested with
Devices(s): N9
Keywords: GConf, libgq-gconf
Created: oniongarlic (22 Mar 2012)
Last edited: hamishwillee (11 Oct 2012)



The MeeGo 1.2 Harmattan Developer documentation has a good, but a bit incomplete examples on how to use GConf for settings. I was able to get it working after some trial and error, as I'm not very familiar with Qt/C++ and the qmake way of doing things, and hope this might be usefull for someone else trying to get the QML based app to talk with GConf.

The GConfItemQmlProxy class from the example can be used directly, but you need to do some modifications to some other files to get it building and working.

Using GConf like this will also disable testing using the Simulator as your are now using platform libraries that do not work with the simulator. (Correct me if I'm wrong here)

Project settings

You need to add gq-conf to PKGCONFIG in your projects .pro file:

PKGCONFIG += gq-gconf

In main.cpp you need to include the QtDeclarative header and the class header for GConfItemQmlProxy:

#include <QtDeclarative>
#include "gconfitemqmlproxy.h"

Then call the following somewhere before you start your QML app:

qmlRegisterType<GConfItemQmlProxy>("example.gconf.item", 1, 0, "GConfItem");

Example main.cpp

#include <QtGui/QApplication>
#include <QtDeclarative>
#include "qmlapplicationviewer.h"
#include "gconfitemqmlproxy.h"
Q_DECL_EXPORT int main(int argc, char *argv[])
QScopedPointer<QApplication> app(createApplication(argc, argv));
qmlRegisterType<GConfItemQmlProxy>("example.gconf.item", 1, 0, "GConfItem");
QmlApplicationViewer viewer;
return app->exec();

Using it in your QML app

First you need to import the GConfItem into your QML file and then add the GConfItems you need and connect your settings variables with the GConfItems.

Example QML Page

import QtQuick 1.1
import 1.0
import org.tal.gconf.item 1.0
Page {
property bool useSound: gconfUseSound.value
onUseSoundChanged: { console.debug(useSound ? "Using sound" : "Muted"); gconfUseSound.value=useSound; }
GConfItem { id: gconfUseSound; key: "/apps/example/use_sound"; defaultValue: true; }
This page was last modified on 11 October 2012, at 01:20.
38 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.