summaryrefslogtreecommitdiff
path: root/src/qml/jsruntime/qv4object.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-02-17 13:36:00 +0100
committerUlf Hermann <ulf.hermann@qt.io>2023-03-24 12:12:06 +0100
commite9f650cad82e7eff2234cdf2d37bb9b1bb25d27d (patch)
tree7db201be0c62d06d8c7815817eb291de66c2437b /src/qml/jsruntime/qv4object.cpp
parentafa15792eb78caa03260670989b22280886eb0a4 (diff)
downloadqtdeclarative-e9f650cad82e7eff2234cdf2d37bb9b1bb25d27d.tar.gz
Models: Straighten out model and modelData properties
If there is more than one role, just return the whole model item as modelData. This makes sure we can always require modelData. That's a basic precondition for writing delegates that work with any model. The test shows that model and modelData behave quite erratically in the different cases, but much of this cannot be changed anymore. At least they are now both available in all cases. Furthermore, provide modelData as anonymous property of model. This way, if you have a model that can be singular, and a role that will be an empty string if the model is singular, you can just write: SomeDelegate { required property var model someData: model[role] } Task-number: QTBUG-111176 Task-number: QTBUG-110980 Task-number: QTBUG-104752 Change-Id: Ie200be467df2098d817b85b03d2409267722b596 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4object.cpp')
-rw-r--r--src/qml/jsruntime/qv4object.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp
index d58a712147..b3b907352b 100644
--- a/src/qml/jsruntime/qv4object.cpp
+++ b/src/qml/jsruntime/qv4object.cpp
@@ -177,7 +177,7 @@ void Object::defineAccessorProperty(StringOrSymbol *name, VTable::Call getter, V
QV4::Scope scope(v4);
ScopedProperty p(scope);
QString n = name->toQString();
- if (n.at(0) == QLatin1Char('@'))
+ if (!n.isEmpty() && n.at(0) == QLatin1Char('@'))
n = QChar::fromLatin1('[') + QStringView{n}.mid(1) + QChar::fromLatin1(']');
if (getter) {
ScopedString getName(scope, v4->newString(QString::fromLatin1("get ") + n));