Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmlsettings.cpp File Reference

(87115131e7444259cf118dbc86be914b66a1d1b7)

#include "qqmlsettings_p.h"
#include <qcoreevent.h>
#include <qcoreapplication.h>
#include <qloggingcategory.h>
#include <qsettings.h>
#include <qpointer.h>
#include <qjsvalue.h>
#include <qqmlinfo.h>
#include <qdebug.h>
#include <qhash.h>
#include "moc_qqmlsettings_p.cpp"
+ Include dependency graph for qqmlsettings.cpp:

Go to the source code of this file.

Classes

class  QQmlSettingsPrivate
 

Variables

static QT_BEGIN_NAMESPACE const int settingsWriteDelay = 500
 \qmlmodule Qt.labs.settings 1.0 \title Qt Labs Settings QML Types
 

Variable Documentation

◆ settingsWriteDelay

QT_BEGIN_NAMESPACE const int settingsWriteDelay = 500
static

\qmlmodule Qt.labs.settings 1.0 \title Qt Labs Settings QML Types

Deprecated
[6.5] Use \l [QML] {QtCore::}{Settings} from Qt QML Core instead.

Provides persistent platform-independent application settings.

To use this module, import the module with the following line:

import Qt.labs.settings
\qmltype Settings

! \instantiates QQmlSettings \inqmlmodule Qt.labs.settings

Deprecated
[6.5] Use \l [QML] {QtCore::}{Settings} from Qt QML Core instead.

Provides persistent platform-independent application settings.

The Settings type provides persistent platform-independent application settings.

Note
This type is made available by importing the Qt.labs.settings module. {Types in the Qt.labs module are not guaranteed to remain compatible in future versions.}

Users normally expect an application to remember its settings (window sizes and positions, options, etc.) across sessions. The Settings type enables you to save and restore such application settings with the minimum of effort.

Individual setting values are specified by declaring properties within a Settings element. All \l {QML Value Types}{value type} properties are supported. The recommended approach is to use property aliases in order to get automatic property updates both ways. The following example shows how to use Settings to store and restore the geometry of a window.

\qml import QtQuick.Window import Qt.labs.settings

Window { id: window

width: 800 height: 600

Settings { property alias x: window.x property alias y: window.y property alias width: window.width property alias height: window.height } } \endqml

At first application startup, the window gets default dimensions specified as 800x600. Notice that no default position is specified - we let the window manager handle that. Later when the window geometry changes, new values will be automatically stored to the persistent settings. The second application run will get initial values from the persistent settings, bringing the window back to the previous position and size.

A fully declarative syntax, achieved by using property aliases, comes at the cost of storing persistent settings whenever the values of aliased properties change. Normal properties can be used to gain more fine-grained control over storing the persistent settings. The following example illustrates how to save a setting on component destruction.

\qml import QtQuick import Qt.labs.settings

Item { id: page

state: settings.state

states: [ State { name: "active" ... }, State { name: "inactive" ... } ]

Settings { id: settings property string state: "active" }

Component.onDestruction: { settings.state = page.state } } \endqml

Notice how the default value is now specified in the persistent setting property, and the actual property is bound to the setting in order to get the initial value from the persistent settings.

Definition at line 206 of file qqmlsettings.cpp.

Referenced by QQmlSettingsPrivate::_q_propertyChanged().