Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-118847

cpp object property getter is called too often for local qml var access

    XMLWordPrintable

Details

    • All

    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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qtqmlteam Qt Qml Team User
              steve.k.chiu Steve K. Chiu
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes