[PySide6]super().__init__() only calls first parent's __init__ if a class inherits QMainWindow and has multiple inheritance
-
class_test.py
import os import sys from PySide6.QtWidgets import QApplication, QMainWindow class First: def __init__(self): print('First init') super().__init__() def __del__(self): print('First del') class Second(): def __init__(self): print('Second init') super().__init__() self.second = 2 def __del__(self): print('Second del') class Third(QMainWindow, Second): def __init__(self): print('Third init') super().__init__() print(f'senond={self.second}') # error in PySide6, self.second, object has no attribute 'second' def __del__(self): print('Third del') def main(): app = QApplication(sys.argv) ob = Third() if __name__ == '__main__': main()
The result:
d:\Codes\Python\automation>class_test.py
Third init
Traceback (most recent call last):
File "D:\Codes\Python\automation\class_test.py", line 41, in <module>
main()
File "D:\Codes\Python\automation\class_test.py", line 37, in main
ob = Third()
File "D:\Codes\Python\automation\class_test.py", line 29, in init
print(f'senond={self.second}')
AttributeError: 'Third' object has no attribute 'second'
Third delIf I change PySide6 to PyQt5, or set 'class Third(First, Second)', the scirpt runs without any error.
Is it an error in PySide6? -
Hi,
Did you check PySide2 as well ?
-
@SGaist I don't have PySide2 installed.
My app runs well when I use PyQt5, but when I tried my app with PySide6, I met the error.
I need to writeclass Third(QMainWindow, Second): def __init__(self): print('Third init') #super().__init__() QMainWindow.__init__(self) Second.__init__(self)
I must refer to the base classes name explicitly in PySide6.
-
If not already existing, you should open a ticket on the bug tracker about that matter.