diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-23 09:50:53 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-23 14:08:28 +0200 |
commit | 797a8f2aaaa8133ea8a54d9e4b91ba531fab3070 (patch) | |
tree | 047eb128e093252ae120b64f2c4278088738857f /tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | |
parent | 1596dbf081ff52d3fe07fdccfd69ffdf1b28e92c (diff) |
QQmlEngine: Add method to explicitly capture a property
Also, use that method to capture the uiLanguage notify signal.
Previously the wrong signal was captured. The test still happened to
pass because we manually re-evaluated all bindings when the uiLanguage
property changed. Add a test which avoid that.
Change-Id: I3961b60b365a8705930936f20881421bd4ceffe5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlengine/tst_qqmlengine.cpp')
-rw-r--r-- | tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index ff8d6e2b2c..1e9b6434c4 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -1195,34 +1195,47 @@ void tst_qqmlengine::createComponentOnSingletonDestruction() void tst_qqmlengine::uiLanguage() { - QQmlEngine engine; + { + QQmlEngine engine; - QObject::connect(&engine, &QJSEngine::uiLanguageChanged, [&engine]() { - engine.retranslate(); - }); + QObject::connect(&engine, &QJSEngine::uiLanguageChanged, [&engine]() { + engine.retranslate(); + }); - QSignalSpy uiLanguageChangeSpy(&engine, SIGNAL(uiLanguageChanged())); + QSignalSpy uiLanguageChangeSpy(&engine, SIGNAL(uiLanguageChanged())); - QQmlComponent component(&engine, testFileUrl("uiLanguage.qml")); + QQmlComponent component(&engine, testFileUrl("uiLanguage.qml")); - QTest::ignoreMessage(QtMsgType::QtWarningMsg, (component.url().toString() + ":2:1: QML QtObject: Binding loop detected for property \"textToTranslate\"").toLatin1()); - QScopedPointer<QObject> object(component.create()); - QVERIFY(!object.isNull()); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, (component.url().toString() + ":2:1: QML QtObject: Binding loop detected for property \"textToTranslate\"").toLatin1()); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); - QVERIFY(engine.uiLanguage().isEmpty()); - QCOMPARE(object->property("numberOfTranslationBindingEvaluations").toInt(), 1); + QVERIFY(engine.uiLanguage().isEmpty()); + QCOMPARE(object->property("numberOfTranslationBindingEvaluations").toInt(), 1); - QTest::ignoreMessage(QtMsgType::QtWarningMsg, (component.url().toString() + ":2:1: QML QtObject: Binding loop detected for property \"textToTranslate\"").toLatin1()); - engine.setUiLanguage("TestLanguage"); - QCOMPARE(object->property("numberOfTranslationBindingEvaluations").toInt(), 2); - QCOMPARE(object->property("chosenLanguage").toString(), "TestLanguage"); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, (component.url().toString() + ":2:1: QML QtObject: Binding loop detected for property \"textToTranslate\"").toLatin1()); + engine.setUiLanguage("TestLanguage"); + QCOMPARE(object->property("numberOfTranslationBindingEvaluations").toInt(), 2); + QCOMPARE(object->property("chosenLanguage").toString(), "TestLanguage"); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, (component.url().toString() + ":2:1: QML QtObject: Binding loop detected for property \"textToTranslate\"").toLatin1()); + engine.evaluate("Qt.uiLanguage = \"anotherLanguage\""); + QCOMPARE(engine.uiLanguage(), QString("anotherLanguage")); + QCOMPARE(object->property("numberOfTranslationBindingEvaluations").toInt(), 3); + QCOMPARE(object->property("chosenLanguage").toString(), "anotherLanguage"); + } + + { + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("uiLanguage.qml")); - QTest::ignoreMessage(QtMsgType::QtWarningMsg, (component.url().toString() + ":2:1: QML QtObject: Binding loop detected for property \"textToTranslate\"").toLatin1()); - engine.evaluate("Qt.uiLanguage = \"anotherLanguage\""); - QCOMPARE(engine.uiLanguage(), QString("anotherLanguage")); - QCOMPARE(object->property("numberOfTranslationBindingEvaluations").toInt(), 3); - QCOMPARE(object->property("chosenLanguage").toString(), "anotherLanguage"); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, (component.url().toString() + ":2:1: QML QtObject: Binding loop detected for property \"textToTranslate\"").toLatin1()); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + + engine.setUiLanguage("TestLanguage"); + QCOMPARE(object->property("chosenLanguage").toString(), "TestLanguage"); + } } QTEST_MAIN(tst_qqmlengine) |