Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creating ListElements Dynamically Outside Parent Component
Qt 6.11 is out! See what's new in the release blog

Creating ListElements Dynamically Outside Parent Component

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.2k Views 1 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.
  • BonganiB Offline
    BonganiB Offline
    Bongani
    wrote on last edited by Bongani
    #1

    I have a component which i load

        Component{
            id:viewComp
            property alias compListMode: viewcompmodel
    
            Item{
                anchors.fill:parent
                id: mainItem
    
                ListView{
                    id:viewcomplist
                    model: viewcompmodel
                    delegate: categoryDelegate
                }
    
                ListModel{
                    id:viewcompmodel
                }
    
                Component {
                    id: categoryDelegate
                    Column {
                        width: 200
    
                        Rectangle {
                            id: categoryItem
                            border.color: "black"
                            border.width: 5
                            color: "white"
                            height: 50
                            width: 200
    
                            Text {
                                anchors.verticalCenter: parent.verticalCenter
                                x: 15
                                font.pixelSize: 24
                                text: Name
                            }
                        }
    
                    }
                }
            }
        }
    

    i need to dynamically create ListElements and SubElements for the "viewcompmodel" List Model outside of the component. How do i go about it ?

    I tried

    viewComp.compListMode.append(createListElement())
    
        function createListElement(elementname) {
            return {
                categoryName: elementname
            };
        }
    

    and i get the Error :

    Component objects cannot declare new properties
    

    and when this also give me fatal errors :

    
        function createListElement(elementname) {
            return {
                Name: "elementname"
               ListElement{
                     name: "Somenam"
                 }
            };
        }
    
    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! See Dynamic QML Object Creation from JavaScript.

      BonganiB 1 Reply Last reply
      1
      • ? A Former User

        Hi! See Dynamic QML Object Creation from JavaScript.

        BonganiB Offline
        BonganiB Offline
        Bongani
        wrote on last edited by
        #3
        This post is deleted!
        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