Python 3.11 和 pyside 6,多重继承

问题描述 投票:0回答:0

我不明白的行为,因为我们从 pyqt4 传递到 pyside6

class Girl(QtCore.QObject):
  def __init__(self, genre="women"):
    QtCore.QObject.__init__(self)
    self.genre = genre

class Student(QtCore.QThread, Girl):
  def __init__(self, fname, lname):
    QtCore.QThread.__init__(self)    

  def printname(self):
    print(f"genre: {self.genre}")
  


x = Student("Mike", "Olsen")
x.printname()

我在 QtCore.QThread.init(self)

行上收到以下错误

RuntimeError:您无法在中初始化 PySide6.QtCore.QThread 对象 给学生上课两次!

我不明白为什么。

如果我这样说我就会理解:

class Student(QtCore.QThread, Girl):
  def __init__(self, fname, lname):
    Girl.__init__(self)
    QtCore.QThread.__init__(self)    

因为 QObject 已经通过 Girl 构造函数初始化了

为什么我不使用以下代码重现相同的错误?

class Person(QtCore.QObject):
  def __init__(self, fname, lname):
    QtCore.QObject.__init__(self)
    self.firstname = fname
    self.lastname = lname

  def printname(self):
    print(self.firstname, self.lastname)

class Girl(QtCore.QObject):
  def __init__(self, genre="women"):
    QtCore.QObject.__init__(self)
    self.genre = genre

class Student2(Person, Girl):
  def __init__(self, fname, lname):
    Person.__init__(self, fname, lname)

  def printname(self):
    print(f"genre: {self.genre}")
  
x = Student2("Mike", "Olsen")
x.printname()
python qt pyqt pyside pyside6
© www.soinside.com 2019 - 2024. All rights reserved.