[PyQt] Cooperative multi-inheritance with QObject + QRunner

Elvis Stansvik elvstone at gmail.com
Tue May 31 12:20:21 BST 2016


Den 31 maj 2016 11:01 fm skrev "Phil Thompson" <phil at riverbankcomputing.com
>:
>
> On 31 May 2016, at 8:53 am, Elvis Stansvik <elvstone at gmail.com> 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)
> >
> >    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?
>
> Correct - the usual restrictions on multiple inheritance of C++ classes.

Alright, thanks.

In the end I've reworked the code so I don't even need the threading, but
good to know.

Elvis

>
> Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160531/5dab47ac/attachment.html>


More information about the PyQt mailing list