Settings: Allow settings locations in resource file system
Pick-to: 6.6 6.5 Fixes: QTBUG-116681 Change-Id: If08f584bf83b75faf5ed0b73962b90c16fc1d016 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
This commit is contained in:
parent
75a33aceab
commit
16002e56fd
|
@ -2,15 +2,18 @@
|
|||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#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 <QtQml/qjsvalue.h>
|
||||
#include <QtQml/qqmlfile.h>
|
||||
#include <QtQml/qqmlinfo.h>
|
||||
|
||||
#include <QtCore/qcoreapplication.h>
|
||||
#include <QtCore/qcoreevent.h>
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <QtCore/qhash.h>
|
||||
#include <QtCore/qloggingcategory.h>
|
||||
#include <QtCore/qpointer.h>
|
||||
#include <QtCore/qsettings.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
@ -236,7 +239,9 @@ QSettings *QQmlSettingsPrivate::instance() const
|
|||
return settings;
|
||||
|
||||
QQmlSettings *q = const_cast<QQmlSettings *>(q_func());
|
||||
settings = location.isLocalFile() ? new QSettings(location.toLocalFile(), QSettings::IniFormat, q) : new QSettings(q);
|
||||
settings = QQmlFile::isLocalFile(location)
|
||||
? new QSettings(QQmlFile::urlToLocalFileOrQrc(location), QSettings::IniFormat, q)
|
||||
: new QSettings(q);
|
||||
|
||||
if (settings->status() != QSettings::NoError) {
|
||||
// TODO: can't print out the enum due to the following error:
|
||||
|
|
|
@ -23,6 +23,13 @@ qt_internal_add_test(tst_qqmlsettings
|
|||
TESTDATA ${test_data}
|
||||
)
|
||||
|
||||
qt_add_resources(tst_qqmlsettings "test_settings"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
"test_settings.ini"
|
||||
)
|
||||
|
||||
qt_internal_extend_target(tst_qqmlsettings CONDITION ANDROID OR IOS
|
||||
DEFINES
|
||||
QT_QMLTEST_DATADIR=":/data"
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
import QtQml
|
||||
import QtCore
|
||||
|
||||
Settings {
|
||||
category: "test"
|
||||
location: "qrc:/test_settings.ini"
|
||||
property string text
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
# ini file in resources
|
||||
[test]
|
||||
text=from resource
|
|
@ -33,6 +33,7 @@ private slots:
|
|||
void siblings();
|
||||
void initial();
|
||||
void noApplicationIdentifiersSet();
|
||||
void fromResources();
|
||||
};
|
||||
|
||||
// ### Replace keyValueMap("foo", "bar") with QVariantMap({{"foo", "bar"}})
|
||||
|
@ -493,6 +494,17 @@ void tst_QQmlSettings::noApplicationIdentifiersSet()
|
|||
QVERIFY(!settings.value("success").toBool());
|
||||
}
|
||||
|
||||
void tst_QQmlSettings::fromResources()
|
||||
{
|
||||
QQmlEngine engine;
|
||||
QQmlComponent component(&engine, testFileUrl("resources.qml"));
|
||||
QVERIFY2(component.isReady(), qPrintable(component.errorString()));
|
||||
QScopedPointer<QObject> root(component.create());
|
||||
QVERIFY(!root.isNull());
|
||||
|
||||
QCOMPARE(root->property("text").toString(), QLatin1String("from resource"));
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QQmlSettings)
|
||||
|
||||
#include "tst_qqmlsettings.moc"
|
||||
|
|
Loading…
Reference in New Issue