首页 > 其他 > 详细

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

时间:2015-09-20 16:11:51      阅读:1632      评论:0      收藏:0      [点我收藏+]

如果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_())

 输出结果为:

技术分享

 

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

原文:http://www.cnblogs.com/ribavnu/p/4823424.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!