246 QQmlSettings *q =
const_cast<QQmlSettings *>(q_func());
247 settings = QQmlFile::isLocalFile(location)
248 ?
new QSettings(QQmlFile::urlToLocalFileOrQrc(location), QSettings::IniFormat, q)
251 if (settings->status() != QSettings::NoError) {
254 qmlWarning(q) <<
"Failed to initialize QSettings instance. Status code is: " <<
int(settings->status());
256 if (settings->status() == QSettings::AccessError) {
257 QStringList missingIdentifiers = {};
258 if (QCoreApplication::organizationName().isEmpty())
259 missingIdentifiers.append(u"organizationName"_s);
260 if (QCoreApplication::organizationDomain().isEmpty())
261 missingIdentifiers.append(u"organizationDomain"_s);
262 if (QCoreApplication::applicationName().isEmpty())
263 missingIdentifiers.append(u"applicationName"_s);
265 if (!missingIdentifiers.isEmpty()) {
267 QString formattedList = QStringLiteral(
"QList(\"")
268 + missingIdentifiers.join(QStringLiteral(
"\", \"")) + QStringLiteral(
"\")");
269 qmlWarning(q) <<
"The following application identifiers have not been set: " << formattedList;
271 qmlWarning(q) <<
"The following application identifiers have not been set: "
272 << missingIdentifiers;
280 if (!category.isEmpty())
281 settings->beginGroup(category);
308 const QMetaObject *mo = q->metaObject();
309 const int offset = QQmlSettings::staticMetaObject.propertyCount();
310 const int count = mo->propertyCount();
312 for (
int i = offset; i < count; ++i) {
313 QMetaProperty property = mo->property(i);
314 const QString propertyName = QString::fromUtf8(property.name());
316 const QVariant previousValue = readProperty(property);
317 const QVariant currentValue = instance()->value(propertyName,
320 if (!currentValue.isNull() && (!previousValue.isValid()
321 || (currentValue.canConvert(previousValue.metaType())
322 && previousValue != currentValue))) {
323 property.write(q, currentValue);
324 qCDebug(lcQmlSettings) <<
"QQmlSettings: load" << property.name() <<
"setting:" << currentValue <<
"default:" << previousValue;
329 if (!instance()->contains(propertyName))
334 static const int propertyChangedIndex = mo->indexOfSlot(
"_q_propertyChanged()");
335 QMetaObject::connect(q, property.notifySignalIndex(), q, propertyChangedIndex);
342 QHash<
const char *, QVariant>::const_iterator it = changedProperties.constBegin();
343 while (it != changedProperties.constEnd()) {
344 instance()->setValue(QString::fromUtf8(it.key()), it.value());
345 qCDebug(lcQmlSettings) <<
"QQmlSettings: store" << it.key() <<
":" << it.value();
348 changedProperties.clear();
354 const QMetaObject *mo = q->metaObject();
355 const int offset = QQmlSettings::staticMetaObject.propertyCount() ;
356 const int count = mo->propertyCount();
357 for (
int i = offset; i < count; ++i) {
358 const QMetaProperty &property = mo->property(i);
359 const QVariant value = readProperty(property);
360 changedProperties.insert(property.name(), value);
361 qCDebug(lcQmlSettings) <<
"QQmlSettings: cache" << property.name() <<
":" << value;
363 timer.start(settingsWriteDelay, q);