Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.5.7, 6.7.3, 6.7, 6.8.0 Beta2, 6.9.0 FF
-
5.6.3, 5.12.6, 5.14.0, 6.7.3
-
c7111871a (dev), e91c9a914 (6.8), 8c97fc274 (6.7), 6238876db (tqtc/lts-6.5)
Description
Consider:
#include <QCoreApplication> #include <QDebug> #include <QQmlApplicationEngine> class Object : public QObject { Q_OBJECT Q_PROPERTY(QStringList strings READ strings CONSTANT) public: QStringList strings() const { static unsigned callCounter = 0; qDebug() << Q_FUNC_INFO << "called" << ++callCounter << "times"; QStringList ret; for (int i = 0; i < 10; ++i) ret.append(QString::number(i)); return ret; } }; int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QJSEngine engine; engine.installExtensions(QJSEngine::ConsoleExtension); qmlRegisterUncreatableType<Object>("App", 1, 0, "Object", QStringLiteral("Use 'object'")); engine.globalObject().setProperty(QStringLiteral("object"), engine.newQObject(new Object)); // Note how the following snippet causes Object::strings to be called // 2 times + as many times as there are items in the list. engine.evaluate(QStringLiteral("console.log(object.strings)")); } #include "main.moc"
Running this outputs:
QStringList Object::strings() const called 1 times QStringList Object::strings() const called 2 times QStringList Object::strings() const called 3 times QStringList Object::strings() const called 4 times QStringList Object::strings() const called 5 times QStringList Object::strings() const called 6 times QStringList Object::strings() const called 7 times QStringList Object::strings() const called 8 times QStringList Object::strings() const called 9 times QStringList Object::strings() const called 10 times QStringList Object::strings() const called 11 times QStringList Object::strings() const called 12 times js: [0,1,2,3,4,5,6,7,8,9]
The list is clearly read more often than it needs to be.
Attachments
Issue Links
- relates to
-
QTBUG-118847 cpp object property getter is called too often for local qml var access
- Reported