diff options
Diffstat (limited to 'tests/auto/qml/qqmlengine')
41 files changed, 101 insertions, 12 deletions
diff --git a/tests/auto/qml/qqmlengine/data/testEmptyAggregateEmptyComponent.1.qml b/tests/auto/qml/qqmlengine/data/testEmptyAggregateEmptyComponent.1.qml index 812242f146..a37461a173 100644 --- a/tests/auto/qml/qqmlengine/data/testEmptyAggregateEmptyComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testEmptyAggregateEmptyComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testEmptyAggregateEmptyComponent.2.qml b/tests/auto/qml/qqmlengine/data/testEmptyAggregateEmptyComponent.2.qml index a171ee6b28..1dc06ee6ae 100644 --- a/tests/auto/qml/qqmlengine/data/testEmptyAggregateEmptyComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testEmptyAggregateEmptyComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testEmptyAggregateVMEComponent.1.qml b/tests/auto/qml/qqmlengine/data/testEmptyAggregateVMEComponent.1.qml index de40284452..ea945eebb0 100644 --- a/tests/auto/qml/qqmlengine/data/testEmptyAggregateVMEComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testEmptyAggregateVMEComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testEmptyAggregateVMEComponent.2.qml b/tests/auto/qml/qqmlengine/data/testEmptyAggregateVMEComponent.2.qml index 4939087b31..9a4fc53833 100644 --- a/tests/auto/qml/qqmlengine/data/testEmptyAggregateVMEComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testEmptyAggregateVMEComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testEmptyComponent.1.qml b/tests/auto/qml/qqmlengine/data/testEmptyComponent.1.qml index 5cee0341fe..155dbdcb91 100644 --- a/tests/auto/qml/qqmlengine/data/testEmptyComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testEmptyComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testEmptyComponent.2.qml b/tests/auto/qml/qqmlengine/data/testEmptyComponent.2.qml index 2a13822fab..940d54be90 100644 --- a/tests/auto/qml/qqmlengine/data/testEmptyComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testEmptyComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testEmptyExtendEmptyComponent.1.qml b/tests/auto/qml/qqmlengine/data/testEmptyExtendEmptyComponent.1.qml index 2f238175fa..46d20e38bb 100644 --- a/tests/auto/qml/qqmlengine/data/testEmptyExtendEmptyComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testEmptyExtendEmptyComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testEmptyExtendEmptyComponent.2.qml b/tests/auto/qml/qqmlengine/data/testEmptyExtendEmptyComponent.2.qml index d36e95fec3..ffdb30f072 100644 --- a/tests/auto/qml/qqmlengine/data/testEmptyExtendEmptyComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testEmptyExtendEmptyComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testEmptyExtendVMEComponent.1.qml b/tests/auto/qml/qqmlengine/data/testEmptyExtendVMEComponent.1.qml index 53dd5a17e9..ca669a9708 100644 --- a/tests/auto/qml/qqmlengine/data/testEmptyExtendVMEComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testEmptyExtendVMEComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testEmptyExtendVMEComponent.2.qml b/tests/auto/qml/qqmlengine/data/testEmptyExtendVMEComponent.2.qml index e5cd7d60de..a93c3b302c 100644 --- a/tests/auto/qml/qqmlengine/data/testEmptyExtendVMEComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testEmptyExtendVMEComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testEmptyPropertyEmptyComponent.1.qml b/tests/auto/qml/qqmlengine/data/testEmptyPropertyEmptyComponent.1.qml index d98aef2932..5930e12df6 100644 --- a/tests/auto/qml/qqmlengine/data/testEmptyPropertyEmptyComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testEmptyPropertyEmptyComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testEmptyPropertyEmptyComponent.2.qml b/tests/auto/qml/qqmlengine/data/testEmptyPropertyEmptyComponent.2.qml index 7f438aa995..8f929c20b2 100644 --- a/tests/auto/qml/qqmlengine/data/testEmptyPropertyEmptyComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testEmptyPropertyEmptyComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testEmptyPropertyVMEComponent.1.qml b/tests/auto/qml/qqmlengine/data/testEmptyPropertyVMEComponent.1.qml index 83d6226e83..20bde6d0af 100644 --- a/tests/auto/qml/qqmlengine/data/testEmptyPropertyVMEComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testEmptyPropertyVMEComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testEmptyPropertyVMEComponent.2.qml b/tests/auto/qml/qqmlengine/data/testEmptyPropertyVMEComponent.2.qml index 98dfb7241b..10ae369459 100644 --- a/tests/auto/qml/qqmlengine/data/testEmptyPropertyVMEComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testEmptyPropertyVMEComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testIncubatedComponent.qml b/tests/auto/qml/qqmlengine/data/testIncubatedComponent.qml index 50af9c4f16..422637fe31 100644 --- a/tests/auto/qml/qqmlengine/data/testIncubatedComponent.qml +++ b/tests/auto/qml/qqmlengine/data/testIncubatedComponent.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testLoaderComponent.qml b/tests/auto/qml/qqmlengine/data/testLoaderComponent.qml index a04ca41c26..67d7ddd1c9 100644 --- a/tests/auto/qml/qqmlengine/data/testLoaderComponent.qml +++ b/tests/auto/qml/qqmlengine/data/testLoaderComponent.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testReloadComponent.qml b/tests/auto/qml/qqmlengine/data/testReloadComponent.qml index 74442108cd..79d4f29db0 100644 --- a/tests/auto/qml/qqmlengine/data/testReloadComponent.qml +++ b/tests/auto/qml/qqmlengine/data/testReloadComponent.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testScriptComponent.qml b/tests/auto/qml/qqmlengine/data/testScriptComponent.qml index b33eb48461..4952a08a6c 100644 --- a/tests/auto/qml/qqmlengine/data/testScriptComponent.qml +++ b/tests/auto/qml/qqmlengine/data/testScriptComponent.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testTopLevelComponent.qml b/tests/auto/qml/qqmlengine/data/testTopLevelComponent.qml index 6cf8ec4203..a6a1f4d4d3 100644 --- a/tests/auto/qml/qqmlengine/data/testTopLevelComponent.qml +++ b/tests/auto/qml/qqmlengine/data/testTopLevelComponent.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testTransientComponent.1.qml b/tests/auto/qml/qqmlengine/data/testTransientComponent.1.qml index d3e6ffd7cf..c661cb6fe4 100644 --- a/tests/auto/qml/qqmlengine/data/testTransientComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testTransientComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testTransientComponent.2.qml b/tests/auto/qml/qqmlengine/data/testTransientComponent.2.qml index acb0113e61..8b6c7eda4d 100644 --- a/tests/auto/qml/qqmlengine/data/testTransientComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testTransientComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMEAggregateEmptyComponent.1.qml b/tests/auto/qml/qqmlengine/data/testVMEAggregateEmptyComponent.1.qml index a5beede469..8c0596eae4 100644 --- a/tests/auto/qml/qqmlengine/data/testVMEAggregateEmptyComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testVMEAggregateEmptyComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMEAggregateEmptyComponent.2.qml b/tests/auto/qml/qqmlengine/data/testVMEAggregateEmptyComponent.2.qml index 4c8e52f251..39b604d42f 100644 --- a/tests/auto/qml/qqmlengine/data/testVMEAggregateEmptyComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testVMEAggregateEmptyComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMEAggregateVMEComponent.1.qml b/tests/auto/qml/qqmlengine/data/testVMEAggregateVMEComponent.1.qml index 983d6e824c..807203b6c7 100644 --- a/tests/auto/qml/qqmlengine/data/testVMEAggregateVMEComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testVMEAggregateVMEComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMEAggregateVMEComponent.2.qml b/tests/auto/qml/qqmlengine/data/testVMEAggregateVMEComponent.2.qml index fc8e5a0cd4..100b287cfd 100644 --- a/tests/auto/qml/qqmlengine/data/testVMEAggregateVMEComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testVMEAggregateVMEComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMEComponent.1.qml b/tests/auto/qml/qqmlengine/data/testVMEComponent.1.qml index fcfd05c51f..dddf51b926 100644 --- a/tests/auto/qml/qqmlengine/data/testVMEComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testVMEComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMEComponent.2.qml b/tests/auto/qml/qqmlengine/data/testVMEComponent.2.qml index f434406eec..fa508f16ac 100644 --- a/tests/auto/qml/qqmlengine/data/testVMEComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testVMEComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMEExtendEmptyComponent.1.qml b/tests/auto/qml/qqmlengine/data/testVMEExtendEmptyComponent.1.qml index 1dcaec90e6..b36d6ebf14 100644 --- a/tests/auto/qml/qqmlengine/data/testVMEExtendEmptyComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testVMEExtendEmptyComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMEExtendEmptyComponent.2.qml b/tests/auto/qml/qqmlengine/data/testVMEExtendEmptyComponent.2.qml index fd7d7e454c..fce617046b 100644 --- a/tests/auto/qml/qqmlengine/data/testVMEExtendEmptyComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testVMEExtendEmptyComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMEExtendVMEComponent.1.qml b/tests/auto/qml/qqmlengine/data/testVMEExtendVMEComponent.1.qml index d2dab32fc9..39629d47df 100644 --- a/tests/auto/qml/qqmlengine/data/testVMEExtendVMEComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testVMEExtendVMEComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMEExtendVMEComponent.2.qml b/tests/auto/qml/qqmlengine/data/testVMEExtendVMEComponent.2.qml index 813e43896c..a4c947cc17 100644 --- a/tests/auto/qml/qqmlengine/data/testVMEExtendVMEComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testVMEExtendVMEComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMEPropertyEmptyComponent.1.qml b/tests/auto/qml/qqmlengine/data/testVMEPropertyEmptyComponent.1.qml index c6f0b7928b..a87372cd27 100644 --- a/tests/auto/qml/qqmlengine/data/testVMEPropertyEmptyComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testVMEPropertyEmptyComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMEPropertyEmptyComponent.2.qml b/tests/auto/qml/qqmlengine/data/testVMEPropertyEmptyComponent.2.qml index 255138520c..c4b16d8ec9 100644 --- a/tests/auto/qml/qqmlengine/data/testVMEPropertyEmptyComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testVMEPropertyEmptyComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMEPropertyVMEComponent.1.qml b/tests/auto/qml/qqmlengine/data/testVMEPropertyVMEComponent.1.qml index 0ad59b32d3..a18a88884c 100644 --- a/tests/auto/qml/qqmlengine/data/testVMEPropertyVMEComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testVMEPropertyVMEComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMEPropertyVMEComponent.2.qml b/tests/auto/qml/qqmlengine/data/testVMEPropertyVMEComponent.2.qml index 60f72a92fe..eb042e82f8 100644 --- a/tests/auto/qml/qqmlengine/data/testVMEPropertyVMEComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testVMEPropertyVMEComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMETransientEmptyComponent.1.qml b/tests/auto/qml/qqmlengine/data/testVMETransientEmptyComponent.1.qml index 6c7f959f49..1f97e587e0 100644 --- a/tests/auto/qml/qqmlengine/data/testVMETransientEmptyComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testVMETransientEmptyComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMETransientEmptyComponent.2.qml b/tests/auto/qml/qqmlengine/data/testVMETransientEmptyComponent.2.qml index 86060c3998..794686494b 100644 --- a/tests/auto/qml/qqmlengine/data/testVMETransientEmptyComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testVMETransientEmptyComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMETransientVMEComponent.1.qml b/tests/auto/qml/qqmlengine/data/testVMETransientVMEComponent.1.qml index c50fd70dec..f442500c7f 100644 --- a/tests/auto/qml/qqmlengine/data/testVMETransientVMEComponent.1.qml +++ b/tests/auto/qml/qqmlengine/data/testVMETransientVMEComponent.1.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/testVMETransientVMEComponent.2.qml b/tests/auto/qml/qqmlengine/data/testVMETransientVMEComponent.2.qml index 120d249bc0..d57cd8a739 100644 --- a/tests/auto/qml/qqmlengine/data/testVMETransientVMEComponent.2.qml +++ b/tests/auto/qml/qqmlengine/data/testVMETransientVMEComponent.2.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 Item { property bool success: false + required property QtObject componentCache function reportError(s) { console.warn(s) } diff --git a/tests/auto/qml/qqmlengine/data/uiLanguage.qml b/tests/auto/qml/qqmlengine/data/uiLanguage.qml new file mode 100644 index 0000000000..bc20351245 --- /dev/null +++ b/tests/auto/qml/qqmlengine/data/uiLanguage.qml @@ -0,0 +1,9 @@ +import QtQml 2.15 +QtObject { + property string chosenLanguage: Qt.uiLanguage + property string textToTranslate: { + numberOfTranslationBindingEvaluations++; + return qsTr("Translate me maybe"); + } + property int numberOfTranslationBindingEvaluations: 0 +} diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp index 613616ab71..cfbbd2a94c 100644 --- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp +++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp @@ -84,6 +84,7 @@ private slots: void aggressiveGc(); void cachedGetterLookup_qtbug_75335(); void createComponentOnSingletonDestruction(); + void uiLanguage(); public slots: QObject *createAQObjectForOwnershipTest () @@ -425,12 +426,13 @@ void tst_qqmlengine::trimComponentCache() QQmlEngine engine; ComponentCacheFunctions componentCache(engine); - engine.rootContext()->setContextProperty("componentCache", &componentCache); engine.setIncubationController(&componentCache); QQmlComponent component(&engine, testFileUrl(file)); QVERIFY2(component.isReady(), qPrintable(component.errorString())); - QScopedPointer<QObject> object(component.create()); + QScopedPointer<QObject> object(component.createWithInitialProperties({ + {"componentCache", QVariant::fromValue(&componentCache)} + })); QVERIFY(object != nullptr); QCOMPARE(object->property("success").toBool(), true); } @@ -512,6 +514,7 @@ void tst_qqmlengine::failedCompilation() QQmlEngine engine; QQmlComponent component(&engine, testFileUrl(file)); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, "QQmlComponent: Component is not ready"); QVERIFY(!component.isReady()); QScopedPointer<QObject> object(component.create()); QVERIFY(object.isNull()); @@ -602,11 +605,10 @@ void tst_qqmlengine::objectOwnership() { QQmlEngine engine; QQmlComponent c(&engine); - engine.rootContext()->setContextProperty("test", this); QQmlEngine::setObjectOwnership(ptr, QQmlEngine::JavaScriptOwnership); - c.setData("import QtQuick 2.0; Item { property int data: test.createAQObjectForOwnershipTest() ? 0 : 1 }", QUrl()); + c.setData("import QtQuick 2.0; Item { required property QtObject test; property int data: test.createAQObjectForOwnershipTest() ? 0 : 1 }", QUrl()); QVERIFY(c.isReady()); - QObject *o = c.create(); + QObject *o = c.createWithInitialProperties( {{"test", QVariant::fromValue(this)}} ); QVERIFY(o != nullptr); } QTRY_VERIFY(spy.count()); @@ -617,13 +619,13 @@ void tst_qqmlengine::objectOwnership() { QQmlEngine engine; QQmlComponent c(&engine); - engine.rootContext()->setContextProperty("test", ptr); QQmlEngine::setObjectOwnership(ptr, QQmlEngine::JavaScriptOwnership); - c.setData("import QtQuick 2.0; QtObject { property var object: { var i = test; test ? 0 : 1 } }", QUrl()); + c.setData("import QtQuick 2.0; QtObject { required property QtObject test; property var object: { var i = test; test ? 0 : 1 } }", QUrl()); QVERIFY(c.isReady()); - QObject *o = c.create(); + QObject *o = c.createWithInitialProperties({{"test", QVariant::fromValue(ptr)}}); QVERIFY(o != nullptr); - engine.rootContext()->setContextProperty("test", nullptr); + QQmlProperty testProp(o, "test"); + testProp.write(QVariant::fromValue<QObject*>(nullptr)); } QTRY_VERIFY(spy.count()); } @@ -773,6 +775,7 @@ public: }; Q_DECLARE_METATYPE(QList<QQmlAbstractUrlInterceptor::DataType>); + void tst_qqmlengine::urlInterceptor_data() { QTest::addColumn<QUrl>("testFile"); @@ -941,14 +944,15 @@ void tst_qqmlengine::cppSignalAndEval() { ObjectCaller objectCaller; QQmlEngine engine; - engine.rootContext()->setContextProperty(QLatin1String("CallerCpp"), &objectCaller); + qmlRegisterSingletonInstance("Test", 1, 0, "CallerCpp", &objectCaller); QQmlComponent c(&engine); c.setData("import QtQuick 2.9\n" + "import Test 1.0\n" "Item {\n" " property var r: 0\n" " Connections {\n" " target: CallerCpp;\n" - " onDoubleReply: {\n" + " function onDoubleReply() {\n" " eval('var z = 1');\n" " r = a;\n" " }\n" @@ -993,6 +997,11 @@ public: SomeQObjectClass() : QObject(nullptr){} }; +class Dayfly : public QObject +{ + Q_OBJECT +}; + void tst_qqmlengine::singletonInstance() { QQmlEngine engine; @@ -1111,7 +1120,7 @@ void tst_qqmlengine::singletonInstance() { // deleted object - auto dayfly = new QObject{}; + auto dayfly = new Dayfly{}; auto id = qmlRegisterSingletonInstance("Vanity", 1, 0, "Dayfly", dayfly); delete dayfly; QTest::ignoreMessage(QtMsgType::QtWarningMsg, "<Unknown File>: The registered singleton has already been deleted. Ensure that it outlives the engine."); @@ -1172,6 +1181,38 @@ void tst_qqmlengine::createComponentOnSingletonDestruction() QVERIFY(obj); } +void tst_qqmlengine::uiLanguage() +{ + QQmlEngine engine; + + QObject::connect(&engine, &QJSEngine::uiLanguageChanged, [&engine]() { + engine.retranslate(); + }); + + QSignalSpy uiLanguageChangeSpy(&engine, SIGNAL(uiLanguageChanged())); + + 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()); + + 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.evaluate("Qt.uiLanguage = \"anotherLanguage\""); + QCOMPARE(engine.uiLanguage(), QString("anotherLanguage")); + QCOMPARE(object->property("numberOfTranslationBindingEvaluations").toInt(), 3); + QCOMPARE(object->property("chosenLanguage").toString(), "anotherLanguage"); +} + QTEST_MAIN(tst_qqmlengine) #include "tst_qqmlengine.moc" |