Python, mixing PyQt5 and abc.ABCMeta

后端 未结 2 772
攒了一身酷
攒了一身酷 2020-12-22 08:15

I am trying to create an AbstractClass using both abc.ABCMeta and QObject as parents and cannot seems to make it work.

Here is the Base class init. I have Pyqt5 and

相关标签:
2条回答
  • 2020-12-22 08:37

    I solved it using this approach instead:

    class ParamsHandler_Meta(type(QObject), type(abc.ABCMeta)):
        pass
    class ParamsHandlerClass(QObject):
        pass
    class ParamsHandler(ParamsHandlerClass):
        __metaclass__ = ParamsHandler_Meta
        def __init__(self, device_model, cmd_to_get_data, read_only=False):
            super(ParamsHandler, self).__init__()
            self.cmd_to_get_data = cmd_to_get_data
    
    0 讨论(0)
  • 2020-12-22 08:48

    abc.ABCMeta is supposed to be used as a metaclass. So instead of extending it, try:

    class ParamsHandler(pyqtWrapperType):
        __metaclass__ = abc.ABCMeta
    
    0 讨论(0)
提交回复
热议问题