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. DelegateModel, cant insert any object elements
Qt 6.11 is out! See what's new in the release blog

DelegateModel, cant insert any object elements

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 2.8k 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.
  • M Offline
    M Offline
    masterofeye
    wrote on last edited by
    #1

    Hello all,

    i want to filter my model by a property provided also per property. remoteworkstations is a QList<QObject*> with my self definded object. These objects are registered for qml and visible by the debugger. My problem is the items.insert(entry, "test"); has no effect, even if I delete the "if" statement before the insert. Need the model to inherit from abstractmodel or something? Where is my failure?

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQml.Models 2.2
    
    Item {
        width: parent.width
        height: parent.width
        id: root
        property var remoteworkstations
        property string projectname
    
        ListView {
            id: displayListView
            anchors.fill: parent
            spacing: 5
            model: displayDelegateModel
        }
    
        DelegateModel {
            id: displayDelegateModel
    
            delegate: MainSection{
                identifier: Hostname
            }
            model: remoteworkstations
            groups: [
                DelegateModelGroup {
                includeByDefault: false
                name: "test"
                }
            ]
            filterOnGroup: "test"
            Component.onCompleted: {
                var rowCount = remoteworkstations.length; //23
                items.remove(0,rowCount); //0
                for( var i = 0;i < rowCount;i++ ) {
                    var entry = root.remoteworkstations[i]; //Entry visible in the debugger
                    if(root.projectname === entry.AssignedProject.Projectname)
                        items.insert(entry,  "test"); //
                }
                console.log(items.count) //always 0
            }
        }
    
    }
    
    R 1 Reply Last reply
    0
    • M masterofeye

      Hello all,

      i want to filter my model by a property provided also per property. remoteworkstations is a QList<QObject*> with my self definded object. These objects are registered for qml and visible by the debugger. My problem is the items.insert(entry, "test"); has no effect, even if I delete the "if" statement before the insert. Need the model to inherit from abstractmodel or something? Where is my failure?

      import QtQuick 2.7
      import QtQuick.Controls 2.0
      import QtQml.Models 2.2
      
      Item {
          width: parent.width
          height: parent.width
          id: root
          property var remoteworkstations
          property string projectname
      
          ListView {
              id: displayListView
              anchors.fill: parent
              spacing: 5
              model: displayDelegateModel
          }
      
          DelegateModel {
              id: displayDelegateModel
      
              delegate: MainSection{
                  identifier: Hostname
              }
              model: remoteworkstations
              groups: [
                  DelegateModelGroup {
                  includeByDefault: false
                  name: "test"
                  }
              ]
              filterOnGroup: "test"
              Component.onCompleted: {
                  var rowCount = remoteworkstations.length; //23
                  items.remove(0,rowCount); //0
                  for( var i = 0;i < rowCount;i++ ) {
                      var entry = root.remoteworkstations[i]; //Entry visible in the debugger
                      if(root.projectname === entry.AssignedProject.Projectname)
                          items.insert(entry,  "test"); //
                  }
                  console.log(items.count) //always 0
              }
          }
      
      }
      
      R Offline
      R Offline
      Roumed
      wrote on last edited by
      #2

      @masterofeye said in DelegateModel, cant insert any object elements:

      remoteworkstations

      Try to build entry with dummy js-object.

      var entry = {
          prop1: "one",
          prop2: 2
      };
      

      Very important to make object corresponds other content of the model.
      The is from the doc:
      "Creates a new entry at index in a DelegateModel with the values from data that correspond to roles in the model assigned to DelegateModel::model."

      1 Reply Last reply
      0
      • M Offline
        M Offline
        masterofeye
        wrote on last edited by
        #3

        Thx for answer but i got the same results.
        When I try following, before i delete the item list

         var entry2 =items.get(0)
        

        I should get the Item from the model. But the entry2 value hasn't any properties attached. I ecpect that i see the same results like in this row.

        var entry = root.remoteworkstations[i];
        
        R 1 Reply Last reply
        0
        • M masterofeye

          Thx for answer but i got the same results.
          When I try following, before i delete the item list

           var entry2 =items.get(0)
          

          I should get the Item from the model. But the entry2 value hasn't any properties attached. I ecpect that i see the same results like in this row.

          var entry = root.remoteworkstations[i];
          
          R Offline
          R Offline
          Roumed
          wrote on last edited by
          #4

          @masterofeye

          Doc about get()
          So, try

          var entry2 =items.get(0).model
          
          1 Reply Last reply
          0
          • M Offline
            M Offline
            masterofeye
            wrote on last edited by
            #5

            I get what I want now, but the documentation for this not realy intuitive. I think there need's to be more examples, on how to set which property with which value.

            Component.onCompleted: {
                        var rowCount = RemoteWorkstations.length;
                        for( var i = 0;i < rowCount;i++ ) {
                            if( items.get(i).model.modelData.AssignedProject.Projectname === projectname) {
                                 items.get(i).inTest = true
                            }
                        }
                    }
            
            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