本文介绍了如何在python中创建一个从QObject派生的抽象基类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为接口创建一个抽象基类,但我需要它从 QObject 派生以用于信号和插槽.我的类定义如下所示:
I'm trying to create an abstract base class for an interface, but I need it to derive from QObject for signals and slots. My class definition looks like this:
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
有什么想法吗?
谢谢
推荐答案
基于多继承元类冲突
试试
import abc
from PyQt5.QtCore import QObject, pyqtWrapperType
class FinalMeta(pyqtWrapperType, abc.ABCMeta):
pass
class interface_class(QObject, metaclass=FinalMeta):
pass
这篇关于如何在python中创建一个从QObject派生的抽象基类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!