PyQT中多重继承,其中继承的父类有QObject或QObject的子孙类

如果Child多重继承(Parent_1,Parent_2,Parent_3),其super函数

super(Child, self).__init__()

 则会执行继承的最左侧的父类:Parent_1.__init__()

但是如果Parent_2是QObject或QObject的子孙类,

在Child的中__init__()中执行QObject.__init__(self)

则会使Parent_3.__init__(self)被执行

原因不明。。。。。。。。。

例子哈:

from PyQt5.QtCore import  QObject
class Parent_1:
    def __init__(self):
        print('Parent_1.__init__')
        
class Parent_2(Parent_1):
    def __init__(self):
        super(Parent_2, self).__init__()
        print('Parent_2.__init__')
        
class Parent_3:
    def __init__(self):
        print('Parent_3.__init__')      

class Child_2( QObject , Parent_2,Parent_3):
        def __init__(self):
            #QObject.__init__(self) 
            super(QObject, self).__init__()
            #super(Child_2, self).__init__()
            
if __name__ == '__main__': 

    import sys
    from PyQt5.QtWidgets import QApplication
    app = QApplication(sys.argv)  
 #####################################################   

    
    print('---------------------------')
    child_2 =     Child_2()    
  #####################################################   
    sys.exit(app.exec_())

 输出结果为:

原文地址:https://www.cnblogs.com/ribavnu/p/4823424.html