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. "Cannot assign object to list property"
QtWS25 Last Chance

"Cannot assign object to list property"

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 505 Views
  • 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.
  • C Offline
    C Offline
    CrouchEndTiger
    wrote on last edited by
    #1

    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" }
        }
    }
    
    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