我正在尝试为接口(interface)创建一个抽象基类,但我需要它从 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
有什么想法吗?
谢谢
最佳答案
基于 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
关于python - 如何在python中创建一个派生自QObject的抽象基类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46837947/