【问题标题】:How to create an abstract base class in python which derived from QObject如何在python中创建一个派生自QObject的抽象基类
【发布时间】:2018-03-31 23:12:18
【问题描述】:

我正在尝试为接口创建一个抽象基类,但我需要它从 QObject 派生用于信号和插槽。我的类定义如下所示:

import abc
from PyQt5.QtCore import QObject

class interface_class(abc.ABC, QObject):
    pass

它失败了:

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

有什么想法吗?

谢谢

【问题讨论】:

    标签: python pyqt pyqt5


    【解决方案1】:

    基于Multiple inheritance metaclass conflict

    试试

    import abc
    from PyQt5.QtCore import QObject, pyqtWrapperType
    
    class FinalMeta(pyqtWrapperType, abc.ABCMeta):
        pass
    
    class interface_class(QObject, metaclass=FinalMeta):
        pass
    

    【讨论】:

      猜你喜欢
      • 2012-11-26
      • 1970-01-01
      • 1970-01-01
      • 2019-12-05
      • 1970-01-01
      • 1970-01-01
      • 2013-08-30
      • 2013-11-30
      • 2021-07-24
      相关资源
      最近更新 更多