aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlsettings
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-09-11 10:41:57 +0200
committerMitch Curtis <mitch.curtis@qt.io>2018-10-11 13:26:56 +0000
commit1ce94fc0f5311c8d9d7dc50de239a827279edcd9 (patch)
treedfa43e5f70a049d2fa1c3617998dacffc4409e5a /tests/auto/qml/qqmlsettings
parent7ca32bc41c2b5a5f6ea360391ba7e398ad7f961b (diff)
Qt Labs Settings: warn if failed to initialize internal QSettings instance
First, warn the user that the QSettings instance failed to initialize if there was an error. Then, if the error was QSettings::AccessError, print the specific application identifiers that weren't set so they know what they have to do. For example: QML Settings: Failed to initialize QSettings instance. Status code is: 1 QML Settings: The following application identifiers have not been set: QVector("organizationName", "organizationDomain") In my case, the QSettings instance wasn't created on Windows because organizationName wasn't set. Change-Id: I7970209e09b78f785730422c45978775311b96ac Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlsettings')
-rw-r--r--tests/auto/qml/qqmlsettings/tst_qqmlsettings.cpp34
1 files changed, 30 insertions, 4 deletions
diff --git a/tests/auto/qml/qqmlsettings/tst_qqmlsettings.cpp b/tests/auto/qml/qqmlsettings/tst_qqmlsettings.cpp
index b353d23539..b0be799bd5 100644
--- a/tests/auto/qml/qqmlsettings/tst_qqmlsettings.cpp
+++ b/tests/auto/qml/qqmlsettings/tst_qqmlsettings.cpp
@@ -53,6 +53,7 @@ private slots:
void categories();
void siblings();
void initial();
+ void noApplicationIdentifiersSet();
};
// ### Replace keyValueMap("foo", "bar") with QVariantMap({{"foo", "bar"}})
@@ -147,10 +148,6 @@ void tst_QQmlSettings::initTestCase()
{
QQmlDataTest::initTestCase();
- QCoreApplication::setApplicationName("tst_QQmlSettings");
- QCoreApplication::setOrganizationName("QtProject");
- QCoreApplication::setOrganizationDomain("qt-project.org");
-
qmlRegisterType<CppObject>("Qt.test", 1, 0, "CppObject");
}
@@ -158,6 +155,10 @@ void tst_QQmlSettings::init()
{
QSettings settings;
settings.clear();
+
+ QCoreApplication::setApplicationName("tst_QQmlSettings");
+ QCoreApplication::setOrganizationName("QtProject");
+ QCoreApplication::setOrganizationDomain("qt-project.org");
}
void tst_QQmlSettings::cleanup()
@@ -481,6 +482,31 @@ void tst_QQmlSettings::initial()
QCOMPARE(settings->property("value").toString(), QStringLiteral("initial"));
}
+void tst_QQmlSettings::noApplicationIdentifiersSet()
+{
+#ifdef Q_OS_MACOS
+ QSKIP("macOS doesn't complain about empty application identifiers");
+#endif
+
+ QCoreApplication::setApplicationName(QString());
+ QCoreApplication::setOrganizationName(QString());
+ QCoreApplication::setOrganizationDomain(QString());
+
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*QML Settings: Failed to initialize QSettings instance. Status code is: 1"));
+ // Can't set an empty applicationName because QCoreApplication won't allow it, which is why it's not listed here.
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*QML Settings: The following application identifiers have not been set: QVector\\(\"organizationName\", \"organizationDomain\"\\)"));
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("basic.qml"));
+ QScopedPointer<QObject> root(component.create());
+ QVERIFY(root.data());
+ // The value of the QML property will be true because it defaults to it...
+ QVERIFY(root->property("success").toBool());
+ QSettings settings;
+ // ... but the settings' value should be false because it was never loaded.
+ QVERIFY(!settings.value("success").toBool());
+}
+
QTEST_MAIN(tst_QQmlSettings)
#include "tst_qqmlsettings.moc"