[PyQt] Cooperative multi-inheritance with QObject + QRunner
Elvis Stansvik
elvstone at gmail.com
Tue May 31 09:33:41 BST 2016
2016-05-31 10:24 GMT+02:00 Elvis Stansvik <elvstone at gmail.com>:
> 2016-05-31 10:19 GMT+02:00 Barry Scott <barry at barrys-emacs.org>:
>> On Tuesday 31 May 2016 09:53:43 Elvis Stansvik wrote:
>>> Hi all,
>>>
>>> I tried subclassing both QObject and QRunnable, like this:
>>>
>>> class Job(QObject, QRunnable):
>>>
>>> finished = pyqtSignal()
>>>
>>> def __init__(self, *args, **kwargs):
>>> super().__init__(*args, **kwargs)
>>
>> super only call init for QObject()
>> you need to call __init__ for QRunnable.
>
> Hm, I thought that with PyQt5, only a single call is required, since
> PyQt classes now support cooperative multi-inheritance:
>
> http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html#cooperative-multi-inheritance
I think the problem is that QThreadPool.start requires the passed in
object to inherit QRunnable directly, not just as a mixin. I'm just
wondering if there's any way around this, or if I have to create some
proxy QObject through on which I can emit the signals. I can probably
hide such a mechanism pretty well, but it would have been nice if it
worked out of the box.
Elvis
>
> Elvis
>
>>
>>>
>>> def run(self):
>>> pass # Do stuff
>>> self.finished.emit()
>>>
>>> But trying to run it on a QThreadPool with
>>>
>>> job = Job()
>>> QThreadPool.globalInstance().start(job)
>>>
>>> I get
>>>
>>> TypeError: could not convert 'Job' to 'QRunnable'
>>>
>>> Is it impossible to leverage PyQt's support for cooperative
>>> multi-inheritance in this case?
>>>
>>> I'd like the class to be a QObject, so that I can emit signals from
>>> it, but at the same time a QRunnable so that I can run it on a
>>> QThreadPool. AFAIK this is possible from C++, but looks like it won't
>>> work with PyQt?
>>>
>>> Thanks in advance,
>>> Elvis
>>> _______________________________________________
>>> PyQt mailing list PyQt at riverbankcomputing.com
>>> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
More information about the PyQt
mailing list