如何在python中创建一个派生自QObject的抽象基类

时间:2017-10-19 19:56:01

标签: python pyqt pyqt5

我试图为接口创建一个抽象基类,但我需要它从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

有什么想法吗?

感谢

1 个答案:

答案 0 :(得分:2)

基于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