×
Namespaces

Variants
Actions

Using GConf from QML applications

From Nokia Developer Wiki
Jump to: navigation, search

This article explains how to use GConf from QML applications.

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

Contents

Introduction

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;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
viewer.setMainQmlFile(QLatin1String("qml/main.qml"));
viewer.showExpanded();
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 com.nokia.meego 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 04:20.
39 page views in the last 30 days.