Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Return type of QAbstractListModel.roleNames()
Qt 6.11 is out! See what's new in the release blog

Return type of QAbstractListModel.roleNames()

Scheduled Pinned Locked Moved Solved Qt for Python
2 Posts 1 Posters 794 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.
  • R Offline
    R Offline
    Reactionic
    wrote on last edited by
    #1

    Hello, I am trying to create my own model for a ListView. The function looks like below

    def roleNames(self):
            roles = dict()
            roles[self.labelRole] = self.schema[0]
            roles[self.colorRole] = self.schema[1]
            return roles
    

    When I run the project, I get an error about return type of this method.

    "sys:1: RuntimeWarning: Invalid return value in function QAbstractListModel.roleNames, expected hash, got dict."

    In examples, a dictionary is used always. Is something changed in PySide6?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Reactionic
      wrote on last edited by
      #2

      I found a solution like this. Maybe this helps someone else who encounters with the same problem.

      def roleNames(self):
              roles = dict()
              roles[hash(self.labelRole)] = self.schema[0].encode()
              roles[hash(self.colorRole)] = self.schema[1].encode()
              return roles
      
      1 Reply Last reply
      3

      • Login

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