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

QDeclarativeEngine::setObjectOwnership(CppOwnership) deletes objects

XMLWordPrintable

      QDeclarativeView::setObjectOwnership doesn't work as expected.

      In essence, I have a
      Q_INVOKABLE QObject *create() {
      Object *o = new Object;
      o->setObjectName("object x");
      QDeclarativeEngine::setObjectOwnership(o, QDeclarativeEngine::CppOwnership);
      return o;
      }

      Despite the ownership being set to CppOwnership, the above objects gets deleted by QML when create() is called in QML.

      Testcase attached:
      1. Click on the rect. You should see a message on console that an object got created.
      2. Quit/Close the app. The view gets deleted on close. You will see messages from the Object destructor indicating that QML is deleting objects despite ownership being set to Cpp.

        1. main.cpp
          0.8 kB
        2. main.qml
          0.2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            aakenned Aaron Kennedy
            girish Girish Ramakrishnan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes