From 4dfcaa7ee8273914ea8cd9fd232064ce95cb15d1 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 2 Jan 2023 21:48:12 +0100 Subject: QQmlObjectCreator: Do not crash on read-only bindable If the binding was not actually set (because the bindable is readonly) then it's dead after the pop_front. We cannot examine it anymore, and we don't have to. Pick-to: 6.5 6.4 6.2 Fixes: QTBUG-109597 Change-Id: I3bf0ca501aa9ad45a64ad181b685ca6d9d325231 Reviewed-by: Fabian Kosmale --- tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp') diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 66d9dc7324..edb1e9ba80 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -414,6 +414,8 @@ private slots: void internalClassParentGc(); void methodTypeMismatch(); + void doNotCrashOnReadOnlyBindable(); + private: // static void propertyVarWeakRefCallback(v8::Persistent object, void* parameter); static void verifyContextLifetime(const QQmlRefPointer &ctxt); @@ -10355,6 +10357,22 @@ void tst_qqmlecmascript::methodTypeMismatch() QCOMPARE(object->actuals(), QVariantList() << QVariant::fromValue((QObject *)nullptr)); } +void tst_qqmlecmascript::doNotCrashOnReadOnlyBindable() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("readOnlyBindable.qml")); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); +#ifndef QT_NO_DEBUG + QTest::ignoreMessage( + QtWarningMsg, + "setBinding: Could not set binding via bindable interface. " + "The QBindable is read-only."); +#endif + QScopedPointer o(c.create()); + QVERIFY(o); + QCOMPARE(o->property("x").toInt(), 7); +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" -- cgit v1.2.3