Solved Return type of QAbstractListModel.roleNames()
-
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?
-
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