Skip to content

Commit

Permalink
Integrate property binding evaluation fix from qtbase
Browse files Browse the repository at this point in the history
This is basically the same as QTBUG-105204, only with the QML engine
being involved.

Fixes: QTBUG-104982
Pick-to: 6.4 6.3 6.2
Change-Id: I5afaadedcd7af41198702a8f2331703b4f6ef2e7
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
  • Loading branch information
Inkane committed Sep 1, 2022
1 parent 3ebbc68 commit 2879c7c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/qml/qml/qqmlpropertybinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ QUntypedPropertyBinding QQmlPropertyBinding::createFromBoundFunction(const QQmlP

void QQmlPropertyBindingJS::expressionChanged()
{
if (!asBinding()->propertyDataPtr)
auto binding = asBinding();
if (!binding->propertyDataPtr)
return;
const auto currentTag = m_error.tag();
if (currentTag == InEvaluationLoop) {
Expand All @@ -151,8 +152,9 @@ void QQmlPropertyBindingJS::expressionChanged()
return;
}
m_error.setTag(InEvaluationLoop);
asBinding()->evaluateRecursive();
asBinding()->notifyRecursive();
PendingBindingObserverList bindingObservers;
binding->evaluateRecursive(bindingObservers);
binding->notifyNonRecursive(bindingObservers);
m_error.setTag(NoTag);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import QtQuick

Item {
objectName: "redRectangle"
id: redRectangle

property bool b: false
function toggle() { b = !b }
width: b ? 600 : 500

Item {
id: blueRectangle
objectName: "blueRectangle"
// width: b ? (100 + redRectangle.width / 2) : 25
width: b ? redRectangle.width : 25
}

property int blueRectangleWidth: blueRectangle.width
}
23 changes: 23 additions & 0 deletions tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ private slots:
void bindingBoundFunctions();
void qpropertyAndQtBinding();
void qpropertyBindingReplacement();
void qpropertyBindingNoQPropertyCapture();
void deleteRootObjectInCreation();
void onDestruction();
void onDestructionViaGC();
Expand Down Expand Up @@ -7737,6 +7738,28 @@ void tst_qqmlecmascript::qpropertyBindingReplacement()
QCOMPARE(root->objectName(), u"overwritten"_s);
}

void tst_qqmlecmascript::qpropertyBindingNoQPropertyCapture()
{

QQmlEngine engine;
QQmlComponent comp(&engine, testFileUrl("qpropertyBindingNoQPropertyCapture.qml"));
std::unique_ptr<QObject> root(comp.create());
QVERIFY2(root, qPrintable(comp.errorString()));
auto redRectangle = root.get();

QQmlProperty blueRectangleWidth(redRectangle, "blueRectangleWidth", &engine);

auto toggle = [&](){
QMetaObject::invokeMethod(root.get(), "toggle");
};

QCOMPARE(blueRectangleWidth.read().toInt(), 25);
toggle();
QCOMPARE(blueRectangleWidth.read().toInt(), 600);
toggle();
QCOMPARE(blueRectangleWidth.read().toInt(), 25);
}

void tst_qqmlecmascript::deleteRootObjectInCreation()
{
QQmlEngine engine;
Expand Down

0 comments on commit 2879c7c

Please sign in to comment.