Loader cannot be created inside Component def?
-
Component { id: indicComp Loader { /// This loader gives me error while compilation id: loaderInst } Rectangle { color: "red" width: 100 height: 100 } }
-
@Rajeesh_Raveendran said in Loader cannot be created inside Component def?:
Component { id: indicComp Loader { /// This loader gives me error while compilation
It helps to include the error message. A minimal working example reports
Invalid component body specification
, and the static analysis message in Qt CreatorComponents are only allowed to have a single child element
. The second message clarifies the problem, which doesn't depend on the type of items instantiated by the Component.@oria66 said in Loader cannot be created inside Component def?:
You should wrap Loader and Rectangle into a Item...
Component { id: indicComp Item{
This works, at the expense of imposing an extra Item per instance of the component. The problem can also be solved by making the Loader a child of the Rectangle, or the other way around. This preserves the Loader sizing and focus scope behavior without explicit forwarding.
-
@jeremy_k said in Loader cannot be created inside Component def?:
Components are only allowed to have a single child element
I understood.
Components are only allowed to have a single child element
-