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
src_corelib_io_qsettings.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
5QSettings settings("MySoft", "Star Runner");
6QColor color = settings.value("DataPump/bgcolor").value<QColor>();
8
9
11QSettings settings("MySoft", "Star Runner");
12QColor color = palette().background().color();
13settings.setValue("DataPump/bgcolor", color);
15
16
18QSettings settings("/home/petra/misc/myapp.ini",
21
22
24QSettings settings("/Users/petra/misc/myapp.plist",
27
28
30QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Office",
33
34
36settings.setValue("11.0/Outlook/Security/DontTrustInstalledFiles", 0);
38
39
41settings.setValue("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy", "Milkyway");
42settings.setValue("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy\\Sun", "OurStar");
43settings.value("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy\\Default"); // returns "Milkyway"
45
46
48#ifdef Q_OS_DARWIN
49 QSettings settings("grenoullelogique.fr", "Squash");
50#else
51 QSettings settings("Grenoulle Logique", "Squash");
52#endif
54
55
57pos = @Point(100 100)
59
60
61
62windir = C:\Windows
64
65
67QSettings settings("Moose Tech", "Facturo-Pro");
69
70
72QSettings settings("Moose Soft", "Facturo-Pro");
74
75
77QCoreApplication::setOrganizationName("Moose Soft");
78QCoreApplication::setApplicationName("Facturo-Pro");
81
82
84settings.beginGroup("mainwindow");
86settings.setValue("fullScreen", win->isFullScreen());
88
89settings.beginGroup("outputpanel");
93
94
97// settings.group() == "alpha"
98
100// settings.group() == "alpha/beta"
101
103// settings.group() == "alpha"
104
106// settings.group() == ""
108
109
115QList<Login> logins;
116...
117
118QSettings settings;
120for (int i = 0; i < size; ++i) {
122 Login login;
123 login.userName = settings.value("userName").toString();
124 login.password = settings.value("password").toString();
125 logins.append(login);
126}
129
130
132struct Login {
135};
136QList<Login> logins;
137...
138
139QSettings settings;
141for (qsizetype i = 0; i < logins.size(); ++i) {
143 settings.setValue("userName", logins.at(i).userName);
144 settings.setValue("password", logins.at(i).password);
145}
148
149
153settings.setValue("fridge/size", QSize(32, 96));
154settings.setValue("sofa", true);
155settings.setValue("tv", false);
156
158// keys: ["fridge/color", "fridge/size", "sofa", "tv"]
160
161
165// keys: ["color", "size"]
167
168
171settings.setValue("fridge/color", QColor(Qt::white));
172settings.setValue("fridge/size", QSize(32, 96));
173settings.setValue("sofa", true);
174settings.setValue("tv", false);
175
177// keys: ["sofa", "tv"]
179
180
182settings.beginGroup("fridge");
184// keys: ["color", "size"]
186
187
190settings.setValue("fridge/color", QColor(Qt::white));
191settings.setValue("fridge/size", QSize(32, 96));
192settings.setValue("sofa", true);
193settings.setValue("tv", false);
194
196// groups: ["fridge"]
198
199
201settings.beginGroup("fridge");
203// groups: []
205
206
209settings.setValue("interval", 30);
210settings.value("interval").toInt(); // returns 30
211
212settings.setValue("interval", 6.55);
213settings.value("interval").toDouble(); // returns 6.55
215
216
220settings.setValue("monkey", 1);
221settings.setValue("monkey/sea", 2);
222settings.setValue("monkey/doe", 4);
223
224settings.remove("monkey");
226// keys: ["ape"]
228
229
232settings.setValue("ape");
233settings.setValue("monkey", 1);
234settings.setValue("monkey/sea", 2);
235settings.setValue("monkey/doe", 4);
236
240
242// keys: ["ape"]
244
245
248settings.setValue("animal/snake", 58);
249settings.value("animal/snake", 1024).toInt(); // returns 58
250settings.value("animal/zebra", 1024).toInt(); // returns 1024
251settings.value("animal/zebra").toInt(); // returns 0
253
254
258
259
263
264
268
269int main(int argc, char *argv[])
270{
271 const QSettings::Format XmlFormat =
273
274 QSettings settings(XmlFormat, QSettings::UserScope, "MySoft",
275 "Star Runner");
276
277 ...
278}
IOBluetoothDevice * device
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtCore
\inmodule QtCore \reentrant
Definition qiodevice.h:34
\inmodule QtCore
Definition qsettings.h:30
void endGroup()
Resets the group to what it was before the corresponding beginGroup() call.
void beginWriteArray(QAnyStringView prefix, int size=-1)
Adds prefix to the current group and starts writing an array of size size.
void endArray()
Closes the array that was started using beginReadArray() or beginWriteArray().
Format
This enum type specifies the storage format used by QSettings.
Definition qsettings.h:48
@ NativeFormat
Definition qsettings.h:49
void setValue(QAnyStringView key, const QVariant &value)
Sets the value of setting key to value.
void remove(QAnyStringView key)
Removes the setting key and any sub-settings of key.
QVariant value(QAnyStringView key, const QVariant &defaultValue) const
Returns the value for setting key.
int beginReadArray(QAnyStringView prefix)
Adds prefix to the current group and starts reading from an array.
QStringList childKeys() const
Returns a list of all top-level keys that can be read using the QSettings object.
static Format registerFormat(const QString &extension, ReadFunc readFunc, WriteFunc writeFunc, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
QStringList allKeys() const
Returns a list of all keys, including subkeys, that can be read using the QSettings object.
QStringList childGroups() const
Returns a list of all key top-level groups that contain keys that can be read using the QSettings obj...
void beginGroup(QAnyStringView prefix)
Appends prefix to the current group.
void setArrayIndex(int i)
Sets the current array index to i.
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
T value() const &
Definition qvariant.h:516
double toDouble(bool *ok=nullptr) const
Returns the variant as a double if the variant has userType() \l QMetaType::Double,...
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
QMap< QString, QString > map
[6]
int main()
[0]
@ white
Definition qnamespace.h:31
GLsizei GLuint * groups
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint color
[2]
GLfloat GLfloat GLfloat alpha
Definition qopenglext.h:418
ptrdiff_t qsizetype
Definition qtypes.h:165
QWidget * win
Definition settings.cpp:6
QWidget * panel
Definition settings.cpp:7
bool myReadFunc(QIODevice &device, QSettings::SettingsMap &map)
[26]
bool readXmlFile(QIODevice &device, QSettings::SettingsMap &map)
[28]
settings beginGroup("mainwindow")
[12]
QSettings settings("MySoft", "Star Runner")
[0]
QList< Login > logins
settings endGroup()
bool myWriteFunc(QIODevice &device, const QSettings::SettingsMap &map)
[27]
settings setValue("DataPump/bgcolor", color)
bool writeXmlFile(QIODevice &device, const QSettings::SettingsMap &map)
QStringList keys
edit isVisible()
Definition parser.h:19