Loader cannot be created inside Component def?
-
wrote on 17 Jun 2023, 05:28 last edited by
Component { id: indicComp Loader { /// This loader gives me error while compilation id: loaderInst } Rectangle { color: "red" width: 100 height: 100 } }
-
wrote on 18 Jun 2023, 17:10 last edited by oria66
You should wrap Loader and Rectangle into a Item...
Component { id: indicComp Item{ Loader { id: loaderInst } Rectangle { color: "red" width: 100 height: 100 } } }
-
Component { id: indicComp Loader { /// This loader gives me error while compilation id: loaderInst } Rectangle { color: "red" width: 100 height: 100 } }
wrote on 18 Jun 2023, 21:01 last edited by@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.
-
@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.
wrote on 19 Jun 2023, 05:42 last edited by@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
-
1/4