Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Don't understand cause of "Cannot assign object to list property" error
Forum Updated to NodeBB v4.3 + New Features

Don't understand cause of "Cannot assign object to list property" error

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 4 Posters 1.7k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ocgltdO Offline
    ocgltdO Offline
    ocgltd
    wrote on last edited by ocgltd
    #1

    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);
        }
    }
    
    KroMignonK 1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      @ocgltd said in Don't understand cause of "Cannot assign object to list property" error:

      GWDetails

      Probably because it is not an Item based object. My guess its a QObject? body is pointing to some object designed to hold Item based objects?

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      0
      • ocgltdO ocgltd

        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);
            }
        }
        
        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #3

        @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
        

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        1 Reply Last reply
        1
        • ocgltdO Offline
          ocgltdO Offline
          ocgltd
          wrote on last edited by
          #4

          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

          KroMignonK 1 Reply Last reply
          0
          • jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote on last edited by
            #5

            Item.children is a list of Items. Item.data is a list of visual and non-visual objects.

            Asking a question about code? http://eel.is/iso-c++/testcase/

            1 Reply Last reply
            0
            • ocgltdO ocgltd

              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

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by
              #6

              @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 and contentData for Popup component, what is bodyContent?
              Note: it would work with contentData (with is a list of object), but not with contentChildren because is it a list of Item

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved