"Cannot assign a value directly to a grouped property" what is it?
-
Hi. I'm facing with a strange error: "Cannot assign a value directly to a grouped property" when tried to add childs to my component.
there is example of parent QML (Parent.qml):import QtQuick 2.9 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.2 GroupBox { property alias menuItems: itemsList GridLayout { id: itemsList } }
child QML (Child.qml):
import QtQuick 2.9 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.2 Parent { title: qsTr("Child's Title") menuItems { Label { text: "hello" } } }
Main Form QML:
... Child { x: 10 y: 10 width: 300 height: 300 visible: true } ...
Is it possible to add childs to parent QML via alias ?
What I'm doing wrong?But application successfully runs if I remove the following code from Child.qml:
menuItems { Label { text: "hello" } }
Thanks!
-
Hi. I'm facing with a strange error: "Cannot assign a value directly to a grouped property" when tried to add childs to my component.
there is example of parent QML (Parent.qml):import QtQuick 2.9 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.2 GroupBox { property alias menuItems: itemsList GridLayout { id: itemsList } }
child QML (Child.qml):
import QtQuick 2.9 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.2 Parent { title: qsTr("Child's Title") menuItems { Label { text: "hello" } } }
Main Form QML:
... Child { x: 10 y: 10 width: 300 height: 300 visible: true } ...
Is it possible to add childs to parent QML via alias ?
What I'm doing wrong?But application successfully runs if I remove the following code from Child.qml:
menuItems { Label { text: "hello" } }
Thanks!
@r3d9u11 think I should use Loader, but I don't know how to add multiple objects via Loader (or something else)
I didn't find any other way except duplicate GroupBox with all setted properties and logic to all kinds of Child.qml and load it through Loader ;-(
-
You can set default property if you want to add childs to a some non-obvious component. Lets say you have an CustomContainer:
... Item { id: root Text { id: label; ... } Column { id: column } }
And you want childs described into
CustomContainer
automatically be added toColumn
, not insideItem
. For this you can usedefault
modificator for property:... Item { id: root default property alias contentData: column.data ...
So, everything described at
CustomContainer
will be a child of yourColumn
. -
You can set default property if you want to add childs to a some non-obvious component. Lets say you have an CustomContainer:
... Item { id: root Text { id: label; ... } Column { id: column } }
And you want childs described into
CustomContainer
automatically be added toColumn
, not insideItem
. For this you can usedefault
modificator for property:... Item { id: root default property alias contentData: column.data ...
So, everything described at
CustomContainer
will be a child of yourColumn
.@IntruderExcluder many thanks for that hint!
it is a bit confusing design, but it works perfect