简体   繁体   English

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

[英]How to create an abstract base class in python which derived from 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.我正在尝试为接口创建一个抽象基类,但我需要它从 QObject 派生出信号和插槽。 My class definition looks like this:我的类定义如下所示:

import abc
from PyQt5.QtCore import QObject

class interface_class(abc.ABC, QObject):
    pass

It fails with:它失败了:

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

Any ideas?有任何想法吗?

thanks谢谢

Based on Multiple inheritance metaclass conflict基于多继承元类冲突

Try尝试

import abc
from PyQt5.QtCore import QObject, pyqtWrapperType

class FinalMeta(pyqtWrapperType, abc.ABCMeta):
    pass

class interface_class(QObject, metaclass=FinalMeta):
    pass

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 类型注释,例如派生自抽象基础 class 的 class 实例 - Python type annotations for instance of class derived from abstract base class 通常在python中从Base创建Derived类 - Universally create Derived class from Base in python 如何在抽象基类(Python 3+)中创建我希望派生类定义的类级属性? - How do I create a class level property in an abstract base class (Python 3+) that I want derived classes to define? 如何在Python中基类内创建派生类的对象? - How to create object of derived class inside base class in Python? 如何在Python中从基类访问派生类的实例变量 - How to access an instance variable of a derived class from a base class in Python Python - 如何从派生的 class 更新基础 class 变量 - Python - How to update base class variable from derived class 如何从基类动态创建派生类 - How can I dynamically create derived classes from a base class Python:如何将所有服装从基类复制到派生服装 - Python: How to copy all attibutes from base class to derived one 如何为Python中的抽象class创建抽象属性? - How to create an abstract attribute for an abstract class in Python? 如何检查从哪个类方法派生的Python? - How to check in Python from which class methods is derived?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM