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. Too often called createObject
Forum Updated to NodeBB v4.3 + New Features

Too often called createObject

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 495 Views 2 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.
  • K Offline
    K Offline
    KaNe09
    wrote on last edited by KaNe09
    #1
    Rectangle {
        id: rect1
        color: Material.backgroundColor
        ....
        ListView {
            id: listView
            model: myModel
    
            delegate: Rectangle {
                Row {
                    ...
                        Component {
                            id: componentText
                            Text {
                                id: nameLink
                                text: qsTr("Hello World!")
                            }
    
                        }
                        Column {
                            id: column
                            resources:
                            {
                                        for(var i=0; i<modelPath.length; i++) {
                                            var path = modelPath[i]
                                            componentText.createObject(column, {"text": "path name: '" + path })
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    

    If I run the code the first time column has the same number of items as the number of modelPath.length. After a switch was pressed the color changed. Hence the above code is running again and after that my column component has twice as many number of items as the number of modelPath.length.
    The information of the switch comes from another .qml-file.
    Is it possible that the column component are create once?

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      Don't use createObject.

      Column {
          Repeater {
              model: modelPath
              Text {
                  text: "path name: " + modelData
              }
          }
      }
      
      1 Reply Last reply
      0
      • K Offline
        K Offline
        KaNe09
        wrote on last edited by
        #3

        With Repeater I got a column with modelPath entries and each entry has all my paths. I want a column with each line has one path

        GrecKoG 1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

          You can also nest ListViews if that is easier. What does you modelPath data look like?

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          0
          • K KaNe09

            With Repeater I got a column with modelPath entries and each entry has all my paths. I want a column with each line has one path

            GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by
            #5

            @KaNe09 said in Too often called createObject:

            With Repeater I got a column with modelPath entries and each entry has all my paths. I want a column with each line has one path

            That's what the code I pasted does, equivalent to what your imperative code did.
            It creates a Text for each path of your modelPath

            1 Reply Last reply
            1
            • K Offline
              K Offline
              KaNe09
              wrote on last edited by
              #6
              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