Details
-
Bug
-
Resolution: Unresolved
-
P1: Critical
-
6.5.3, 6.6
-
None
Description
We run into a weird issue when access a qml local var that assigned from cpp object property, the cpp object property method is called whenever the local var is accessed.
The code should explain the issue more clearly:
class MySingleton : public QObject { Q_OBJECT QML_ELEMENT QML_SINGLETON Q_PROPERTY(QStringList mark READ mark NOTIFY markChanged) public: explicit MySingleton(QObject* parent = nullptr) : QObject(parent) {} QStringList mark() { qDebug() << "** mark is called"; return { "mark" }; } signals: void markChanged(); };
// Some comments here function example() { var p = MySingleton.mark; if (p.length > 0) print(p); }
the output is:
** mark is called ** mark is called [mark]
that every time p is accessed, the MySingleton::mark() method is called; this only happen to QList return type, primitive return type does not have this issue.
Attachments
Issue Links
- relates to
-
QTBUG-127322 JSON.stringify() on property of type QVariantList reads property for every list element
- Reported
-
QTBUG-81231 QJSEngine and QStringList properties handling, a potential performance issue
- Closed
-
QTBUG-128358 Reduce unnecessary detaches and copies when handling value types and lists
- Reported