Code snippet:
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QObject
import sys
class ParentA:
def __init__(self, x, y):
self.b = x + y
class Child(QObject, ParentA):
def __init__(self, x, y):
QObject.__init__(self) # <- Error is thrown here
z = x + 2
ParentA.__init__(self, z, y)
self.c = "Child specific value"
print("end")
if __name__ == "__main__":
app = QApplication([])
Child(1,2)
sys.exit(app.exec_())
Error message:
Exception has occurred: TypeError ParentB.init() missing 2 required positional arguments: 'x' and 'y'
Error thrown on first line of Child constructor
Using VS code on windows
When you replace QObject with a self-made class, the problem does not appear. Also if you do not call the QObject init function in the Child constructor, there is no problem, but I believe there is no reason why I should refrain from calling the QObject constructor.
class Child(ParentA, QObject)the problem will go away. But really, you should be usingsuperfor cases like this. See the PyQt docs: Support for Cooperative Multi-inheritance.ParentBclass.