Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.6.0
-
None
-
All, tested on Ubuntu and Sailfish OS.
-
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.