• 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_())
    

     输出结果为:

  • 相关阅读:
    NSPredicate的用法、数组去重、比较...
    CocoaPods安装和使用教程
    UITableView学习笔记
    Linux dpkg 命令
    Linux rpm 软件包管理命令
    Linux chmod 文件权限命令
    Linux vi 命令
    分库分表背后那些事儿
    Spring Cloud Feign原理及性能
    linux "No space left on device" 磁盘空间解决办法
  • 原文地址:https://www.cnblogs.com/ribavnu/p/4823424.html
Copyright © 2020-2023  润新知