Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
5.15, 6.5, dev
-
None
Description
QML has this interesting feature that allows binding arbitrary component definitions to QQmlComponent* typed properties without a Component wrapper. But it doesn't work inside inline component definitions. It prints an error on 6.5 and dev, and also crashes on 5.15 if your inline component happens to contain an id.
The following snippet does NOT crash on 5.15, but print the following error on 6.5/dev:
import QtQuick 2.15 QtObject { property QtObject explicit: Loader { sourceComponent: Component { QtObject {} } } property QtObject shortcut: Loader { // Shorthand syntax works fine, as usual. sourceComponent: QtObject {} } component Inline : Loader { // Comment out next line to avoid QML engine error sourceComponent: QtObject {} } }
main.qml:15:26: Cannot assign object of type "QtObject" to property of type "QQmlComponent*" as the former is neither the same as the latter nor a sub-class of it.
Meanwhile, this snippet DOES crash on 5.15, and still prints a warning on 6.5/dev:
import QtQuick 2.15 import QtQuick.Templates 2.15 as T Item { component ABC : T.PageIndicator { id: control delegate: Item {} } ABC {} }
Somehow wrapping that delegate Item in a Component or removing id fixes it.
Reproducible with any type that has a property of Component type. Loader is just one the simplest I found in QtQuick module.
Attachments
Issue Links
- duplicates
-
QTBUG-98859 Implicit conversion to Component doesn't work in inline components
- Closed