2017-10-19 106 views
1

我想爲接口創建抽象基類,但我需要它從QObject派生出信號和插槽。我的類定義是這樣的:如何在從QObject派生的python中創建抽象基類

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

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