Details
-
Bug
-
Resolution: Done
-
P2: Important
-
6.4.0 Beta4
-
d8066adc55 (qt/qtdeclarative/dev) d8066adc55 (qt/tqtc-qtdeclarative/dev)
Description
The idea behind a Component is to avoid creating a new file to declare a new type, and instead create it inline:
Components are often defined by component files - that is, .qml files. The Component type essentially allows QML components to be defined inline, within a QML document, rather than as a separate QML file. This may be useful for reusing a small component within a QML file, or for defining a component that logically belongs with other QML components within a file.
(from the docs at https://doc.qt.io/qt-6/qml-qtqml-component.html)
It seems that qml currently supports top-level Components, which means that Component can also be used in a different file (instead of being used inline as the documentation advertises it for).
Here an example:
//ComponentType.qml import QtQml Component { // [1] id: componentRoot QtObject { objectName: "enclosed" } } //main.qml import QtQuick Item { ComponentType { id: myId // [2] property var myProperty // [3] } }
List of headaches caused by this code:
- [1]: Double Component: The qml file already denotes a component, using a component inside a component means that the component is "two times wrapped into a component" (via the implicit component wrapping). This component is completely useless but it allows even weirder uses because it enables the `ComponentType { /evil stuff here/}` notation (see [2] and [3]). Using Component not as toplevel element means that they cannot be used with the `{}` notation).
- [2]: ids: this Component already has a name, the id is completely ignored in qml/qmlcachegen and is useless (cannot be seen or anywhere). Unfortunately, it makes the logic in qmltc more complicated (as it needs to know if the id is or is not in the compilation unit)
- [3]: Forbidden properties: a Component only contains a name and one item, other stuff like properties/signal/methods are forbidden. But here the qml utility just ignores them.
Subtasks:
- reject top level Components in qmltc
- deprecate top level components (maybe they can be removed in qt7)
- also warn when finding top level components
Attachments
Issue Links
- resulted in
-
QTBUG-109182 qml: do not deprecate top level components in createQmlObject
- Closed