Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

"Cannot assign object to list property"



  • Hi!

    I'm having some trouble assigning a T.Popup root-type to the .children property of another type. I get the error message: "Cannot assign object to list property" Couldn't find any references to the same problem.

    I've got a PresentationPanel type, which should be able to display an arbitrary component for a kind-of "sticker app". It works fine on most types, but it has trouble with my custom ContextMenu type with a base-type of T.Popup.

    Any help would be massively appreciated!

    main.qml:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Popup Bug!")
        color: "#313A68"
    
        DisplayPanel
        {
            x: 100
            y: 100
    
            title: "Context Menu"
            content: MyContextMenu
            {
                visible: true
            }
        }
    }
    
    

    DisplayPanel.qml:

    Rectangle
    {
        radius: 20
        color: "#5AA1BF"
    
        default property alias content: mainPanel.children
    
        implicitWidth: Math.max(
                           titleComponent.width + 2 * priv.padding,
                           mainPanel.width + 2 * priv.padding)
    
        implicitHeight: titleComponent.height + mainPanel.height + 3 * priv.padding
    
        property alias title: titleComponent.text
    
        QtObject
        {
            id: priv
            readonly property real padding: 10
        }
    
        Text
        {
            id: titleComponent
            anchors
            {
                top: parent.top
                left: parent.left
                margins: priv.padding
            }
        }
    
        ColumnLayout
        {
            id: mainPanel
            anchors
            {
                top: titleComponent.bottom
                left: parent.left
                margins: priv.padding
            }
        }
    }
    

    MyContextMenu.qml

    import QtQuick 2.0
    import QtQuick.Templates 2.12 as T
    
    T.Popup
    {
        id:root
    
        implicitWidth: mainView.width
        implicitHeight: mainView.height
    
        margins: 0
    
        function popup(mouseX, mouseY)
        {
            x = mouseX
            y = mouseY
            root.open()
        }
    
        contentItem: ListView
        {
            id: mainView
            model: listModel
    
            width: 100
            height: model.count * 20
    
            delegate: Text
            {
                height: 20
                text: model.text
            }
        }
    
        background: Rectangle
        {
            id: background
            anchors.fill: parent
            color: "#DF69AB"
        }
    
        ListModel
        {
            id: listModel
            ListElement{ text: "Item 1" }
            ListElement{ text: "Item 2" }
            ListElement{ text: "Item 3" }
            ListElement{ text: "Item 4" }
        }
    }
    

Log in to reply