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

Attached property initialisation has started requiring object parent is created within QML

    XMLWordPrintable

Details

    • 4be38abab97f07b999ca3b2da3c45c5423d83dc0

    Description

      From Qt 5.6 onwards function qmlAttachedPropertiesObject() (used to initialise attached objects, see doc http://doc.qt.io/qt-5/qqmlengine.html) has started to require that attached object parent is created within QML. Attached example app that fails to load MyItemAttached attached object since the parent QQuickWindow is not initialised within QML.

      Caused by fix to QTBUG-43581 in https://codereview.qt-project.org/#/c/125708/.

      Wrapping the QML inside a window created within QML works around the issue "import QtQuick.Window 2.2; import MyModule 1.0; Window { MyItem {}}", but is not good solution for us since our attached object is public API and we should not enforce such requirements.

      Explanation in more depth: Id cache used to retrieve attached object returns -1 initially. Id then gets initialised through QQmlEngine. QQmlEngine is fetched using attached property parent object pointer. Unfortunately in our case the attached property parent QQuickWindow is created outside QML code so qmlEngine(object) returns zero and no valid id cache gets created. Later in the construction id cache is created by others so the attached object initialisation starts working.

      Attachments

        For Gerrit Dashboard: QTBUG-57396
        # Subject Branch Project Status CR V

        Activity

          People

            frederik Frederik Gladhorn
            jpetrell Joona Petrell
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes