[Development] Settings API for QML

Nurmi J-P jpnurmi at digia.com
Fri Jun 21 15:48:02 CEST 2013


Returning to the subject, here's a simplified proposal:

    import QtQuick 2.0
    import Qt.labs.settings 1.0

    Item {
        id: window

        width: settings.width
        height: settings.height

        Settings {
            id: settings
            category: "Geometry"

            property int width: 800
            property int height: 600

        Component.onDestruction: {
            settings.width = window.width
            settings.height = window.height

Implementation based on Joao's old prototype: https://codereview.qt-project.org/#change,59149

In short, the idea is to keep the API as minimal as possible, leaving the category/group as the only configurable property. I was delighted to find out that QCoreApplication::applicationName was already exposed to QML, but I would propose exposing organization name too (https://codereview.qt-project.org/#change,59524) in order to provide a bit better control over the settings location. The tricky thing is to get those initialized in pure QML applications before constructing a Settings object. Perhaps Component could have an attached onConstruction signal that would get triggered when construction begins?

J-P Nurmi

More information about the Development mailing list