Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. get method removed from XmlListModel
Forum Updated to NodeBB v4.3 + New Features

get method removed from XmlListModel

Scheduled Pinned Locked Moved Solved Qt 6
2 Posts 1 Posters 398 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.
  • T Offline
    T Offline
    Ttberg
    wrote on last edited by Ttberg
    #1

    On Qt5 I was able to do something like this:

    XmlListModel {
    id: model
    XmlRole { name:"prop1" }
    XmlRole { name:"prop2" }
    XmlRole { name:"prop3" }
    }
    
    onRowsInserted: {
      for (var i = 0; i < model.count; ++i)
    {
    if (model.get(i).prop2 === "testVal2") //do something
    }
    }
    

    On Qt6 this is not possible anymore, as the getter is removed. I found a (in my opinion) workaround to still get the same result:

    XmlListModel {
    id: model
    XmlListModelRole { name:"prop1" }
    XmlListModelRole { name:"prop2" }
    XmlListModelRole { name:"prop3" }
    }
    
    onRowsInserted: {
      for (var i = 0; i < model.count; ++i)
    {
    if (model.data(model.index(i,0), Qt.UserRole+1) === "testVal1") //do something
    }
    }
    

    But if I remove or add XmlListModelRoles, I might also need to change the offset to Qt.UserRole.
    So, why was the get method removed, and is there a better way to solve this?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Ttberg
      wrote on last edited by
      #2

      a suggestion to reimplement this has been created here:
      https://bugreports.qt.io/browse/QTBUG-102267

      in the meantime this function can be used:

      function get(i) {
       var o = {}
       for (var j = 0; j < roles.length; ++j)
       {
        o[roles[j].name] = data(index(i,0), Qt.UserRole + j)  
       }  
      return o 
      }
      
      1 Reply Last reply
      0
      • B Bob64 referenced this topic on

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved