aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLuca Di Sera <luca.disera@qt.io>2024-03-20 15:38:38 +0100
committerLuca Di Sera <luca.disera@qt.io>2024-03-21 21:00:10 +0100
commitc0982b004ac1e7f6b45dccbd0bbaf9604130dd2b (patch)
tree0be0d62bd584ba5b71c1368722400213fae9d513 /tools
parentea18f9f8eb5edaeb4fb7642e44689cbeb90b663b (diff)
qmltc: Avoid overwriting initial properties
When `qmltc` compiles a QML type, it allows the user to set the initial values for the properties of the component at construction time. Due to the order of operations that `qmltc` uses when creating a component, the compiled type keeps track of the properties for which an initial values was set to avoid overriding the value in later phases. For example, a property that is bound by its definition in the original QML file, will have that bound applied after the initial values for the properties are set. To avoid this issue, a type compiled by `qmltc` uses its knowledge of which property was initialized to avoid setting the binding for the property in the later phases. Due to an error in the code-base for `qmltc`, certain bindings for a property are still being set independently of the property having an initial value or not. In particular, one of the branches in `QmltcCodeGenerator::generate_createBindingOnProperty` was not conditioning the generated property binding on whether an initial value was set. For example, a value list property that is bound to an empty list, would have passed by the incorrect branch, so that its value would be overwritten even when the property was provided with an initial value. To avoid the issue, the branch was modified to generate code that takes into account the initialization, or lack thereof, of the property. The test that verifies the initial values behavior was modified to have a representative case for the issue. Task-number: QTBUG-120700 Change-Id: Ic3f56a8774e26ab18d3fd234a1cd28e525672e36 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmltc/qmltccompilerpieces.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/tools/qmltc/qmltccompilerpieces.cpp b/tools/qmltc/qmltccompilerpieces.cpp
index bdb71cff4c..cd1735bc07 100644
--- a/tools/qmltc/qmltccompilerpieces.cpp
+++ b/tools/qmltc/qmltccompilerpieces.cpp
@@ -242,11 +242,13 @@ void QmltcCodeGenerator::generate_createBindingOnProperty(
*block += epilogue;
} else {
QString createBindingForNonBindable =
- u"QT_PREPEND_NAMESPACE(QQmlCppBinding)::createBindingForNonBindable(" + unitVarName
+ u" "_s
+ + u"QT_PREPEND_NAMESPACE(QQmlCppBinding)::createBindingForNonBindable(" + unitVarName
+ u", " + scope + u", " + QString::number(functionIndex) + u", " + target + u", "
+ QString::number(propertyIndex) + u", " + QString::number(valueTypeIndex) + u", "
+ propName + u")";
// Note: in this version, the binding is set implicitly
+ *block << u"if (!initializedCache.contains(\"%1\"))"_s.arg(p.propertyName());
*block << createBindingForNonBindable + u";";
}
}