Don't understand cause of "Cannot assign object to list property" error
-
My QML file below was working fine, and now I want to call a C++ function so I created a "GWDetails" class as described here on Stack Overflow
Now when QML tries to run my file below I get error:
Cannot assign object to list property "body"
on the line below which is " GWDetails {". I dont understand the error above, or what instantiating the GWDetails class affects the body property of the parent object. The only change to this file is 3 lines at the bottom, instantiating the GWDetails class.
GWEdit descends from ODialogSaveCancel which makes propert "body" available, and it is an alias to someitem.children which is obviously a list. The problem seems to occur if I assign anything other than a single item to the body property. So as a workaround I nested my other GWDetails object inside another (to assign a single item to "body"). But shouldn't I be able to assign an array of objects to the list?
Can someone suggest a cause / solution?
import QtQuick 2.0 import QtQuick.Controls 2.12 import QtQuick.Controls.Material 2.12 import QtQuick.Layouts 1.12 import GUIConstants 1.0 import GWDetails 1.0 import "../../../common/ODialog" ODialogSaveCancel { id: dialog title: "Error" Material.theme: Material.Dark Material.accent: Material.Orange x: 20 y: 20 width: parent.width-40 height: parent.height-40 body: [ Item { TabBar { id: bar width: bodyWidth TabButton { background: Rectangle { color: bar.currentIndex === 0 ? gui.colorRGBString(GUIConstants.EColorElement_BackgroundSelected): gui.colorRGBString(GUIConstants.EColorElement_BackgroundAlternate3) } contentItem: Text { text: qsTr("Hardware") opacity: enabled ? 1.0 : 0.3 color: bar.currentIndex === 0 ? gui.colorRGBString(GUIConstants.EColorElement_TextInverted) : gui.colorRGBString(GUIConstants.EColorElement_Text) horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter elide: Text.ElideRight } } TabButton { background: Rectangle { color: bar.currentIndex === 1 ? gui.colorRGBString(GUIConstants.EColorElement_BackgroundSelected): gui.colorRGBString(GUIConstants.EColorElement_BackgroundAlternate3) } contentItem: Text { text: qsTr("Overview") opacity: enabled ? 1.0 : 0.3 color: bar.currentIndex === 1 ? gui.colorRGBString(GUIConstants.EColorElement_TextInverted) : gui.colorRGBString(GUIConstants.EColorElement_Text) horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter elide: Text.ElideRight } } TabButton { background: Rectangle { color: bar.currentIndex === 2 ? gui.colorRGBString(GUIConstants.EColorElement_BackgroundSelected): gui.colorRGBString(GUIConstants.EColorElement_BackgroundAlternate3) } contentItem: Text { text: qsTr("Location") opacity: enabled ? 1.0 : 0.3 color: bar.currentIndex === 2 ? gui.colorRGBString(GUIConstants.EColorElement_TextInverted) : gui.colorRGBString(GUIConstants.EColorElement_Text) horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter elide: Text.ElideRight } } } // Fill area below tabs Rectangle { y: bar.height border { width: 1 color: gui.colorRGBString(GUIConstants.EColorElement_Dialog_Border) } color: gui.colorRGBString(GUIConstants.EColorElement_BackgroundAlternate3) height: bodyHeight - bar.height width: bodyWidth StackLayout { anchors { fill: parent margins: 1 } // width: parent.width-(2*parent.border.width) // height: parent.height-(2*parent.border.width) currentIndex: bar.currentIndex Item { id: homeTab } Item { id: discoverTab } Item { id: activityTab } } } // StackLayout } , // Item // Create an instance of the gateway details interface GWDetails { id: gwDetailsInterface } ] function onCancelClick() { console.log("Got cancel click in gwedit") } Component.onCompleted: { // Request the gateway details from the orchestrator // gwDetailsInterface.fetch(model.uid); } }
-
My QML file below was working fine, and now I want to call a C++ function so I created a "GWDetails" class as described here on Stack Overflow
Now when QML tries to run my file below I get error:
Cannot assign object to list property "body"
on the line below which is " GWDetails {". I dont understand the error above, or what instantiating the GWDetails class affects the body property of the parent object. The only change to this file is 3 lines at the bottom, instantiating the GWDetails class.
GWEdit descends from ODialogSaveCancel which makes propert "body" available, and it is an alias to someitem.children which is obviously a list. The problem seems to occur if I assign anything other than a single item to the body property. So as a workaround I nested my other GWDetails object inside another (to assign a single item to "body"). But shouldn't I be able to assign an array of objects to the list?
Can someone suggest a cause / solution?
import QtQuick 2.0 import QtQuick.Controls 2.12 import QtQuick.Controls.Material 2.12 import QtQuick.Layouts 1.12 import GUIConstants 1.0 import GWDetails 1.0 import "../../../common/ODialog" ODialogSaveCancel { id: dialog title: "Error" Material.theme: Material.Dark Material.accent: Material.Orange x: 20 y: 20 width: parent.width-40 height: parent.height-40 body: [ Item { TabBar { id: bar width: bodyWidth TabButton { background: Rectangle { color: bar.currentIndex === 0 ? gui.colorRGBString(GUIConstants.EColorElement_BackgroundSelected): gui.colorRGBString(GUIConstants.EColorElement_BackgroundAlternate3) } contentItem: Text { text: qsTr("Hardware") opacity: enabled ? 1.0 : 0.3 color: bar.currentIndex === 0 ? gui.colorRGBString(GUIConstants.EColorElement_TextInverted) : gui.colorRGBString(GUIConstants.EColorElement_Text) horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter elide: Text.ElideRight } } TabButton { background: Rectangle { color: bar.currentIndex === 1 ? gui.colorRGBString(GUIConstants.EColorElement_BackgroundSelected): gui.colorRGBString(GUIConstants.EColorElement_BackgroundAlternate3) } contentItem: Text { text: qsTr("Overview") opacity: enabled ? 1.0 : 0.3 color: bar.currentIndex === 1 ? gui.colorRGBString(GUIConstants.EColorElement_TextInverted) : gui.colorRGBString(GUIConstants.EColorElement_Text) horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter elide: Text.ElideRight } } TabButton { background: Rectangle { color: bar.currentIndex === 2 ? gui.colorRGBString(GUIConstants.EColorElement_BackgroundSelected): gui.colorRGBString(GUIConstants.EColorElement_BackgroundAlternate3) } contentItem: Text { text: qsTr("Location") opacity: enabled ? 1.0 : 0.3 color: bar.currentIndex === 2 ? gui.colorRGBString(GUIConstants.EColorElement_TextInverted) : gui.colorRGBString(GUIConstants.EColorElement_Text) horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter elide: Text.ElideRight } } } // Fill area below tabs Rectangle { y: bar.height border { width: 1 color: gui.colorRGBString(GUIConstants.EColorElement_Dialog_Border) } color: gui.colorRGBString(GUIConstants.EColorElement_BackgroundAlternate3) height: bodyHeight - bar.height width: bodyWidth StackLayout { anchors { fill: parent margins: 1 } // width: parent.width-(2*parent.border.width) // height: parent.height-(2*parent.border.width) currentIndex: bar.currentIndex Item { id: homeTab } Item { id: discoverTab } Item { id: activityTab } } } // StackLayout } , // Item // Create an instance of the gateway details interface GWDetails { id: gwDetailsInterface } ] function onCancelClick() { console.log("Got cancel click in gwedit") } Component.onCompleted: { // Request the gateway details from the orchestrator // gwDetailsInterface.fetch(model.uid); } }
@ocgltd said in Don't understand cause of "Cannot assign object to list property" error:
Now when QML tries to run my file below I get error:
Cannot assign object to list property "body"What is the definition of body from component ODialogSaveCancel?
To be able to store QObject instances it should be:property List<QtObject> body
-
body is an alias to the children of a popup, like this:
Popup { default property alias body: bodyContent.children // Expose body to be populated ... }
Since .children is a list I thought this should work
@ocgltd said in Don't understand cause of "Cannot assign object to list property" error:
Since .children is a list I thought this should work
Yes it maybe a list, but a list of what???
I only aware about
contentChildren
andcontentData
forPopup
component, what isbodyContent
?
Note: it would work withcontentData
(with is a list of object), but not with contentChildren because is it a list ofItem