[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Cooperative multi-inheritance with QObject + QRunner
From:       Elvis Stansvik <elvstone () gmail ! com>
Date:       2016-05-31 11:20:21
Message-ID: CAHms=eYeZ2x70aq60VBFztMUP4nmOGcSWnbyMxFMV37q5fhHEA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Den 31 maj 2016 11:01 fm skrev "Phil Thompson" <phil@riverbankcomputing.com
>:
>
> On 31 May 2016, at 8:53 am, Elvis Stansvik <elvstone@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

[Attachment #5 (text/html)]

<p dir="ltr"><br>
Den 31 maj 2016 11:01 fm skrev &quot;Phil Thompson&quot; &lt;<a \
href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>&gt;:<br> \
&gt;<br> &gt; On 31 May 2016, at 8:53 am, Elvis Stansvik &lt;<a \
href="mailto:elvstone@gmail.com">elvstone@gmail.com</a>&gt; wrote:<br> &gt; &gt;<br>
&gt; &gt; Hi all,<br>
&gt; &gt;<br>
&gt; &gt; I tried subclassing both QObject and QRunnable, like this:<br>
&gt; &gt;<br>
&gt; &gt; class Job(QObject, QRunnable):<br>
&gt; &gt;<br>
&gt; &gt;      finished = pyqtSignal()<br>
&gt; &gt;<br>
&gt; &gt;      def __init__(self, *args, **kwargs):<br>
&gt; &gt;            super().__init__(*args, **kwargs)<br>
&gt; &gt;<br>
&gt; &gt;      def run(self):<br>
&gt; &gt;            pass   # Do stuff<br>
&gt; &gt;            self.finished.emit()<br>
&gt; &gt;<br>
&gt; &gt; But trying to run it on a QThreadPool with<br>
&gt; &gt;<br>
&gt; &gt;      job = Job()<br>
&gt; &gt;      QThreadPool.globalInstance().start(job)<br>
&gt; &gt;<br>
&gt; &gt; I get<br>
&gt; &gt;<br>
&gt; &gt;      TypeError: could not convert &#39;Job&#39; to &#39;QRunnable&#39;<br>
&gt; &gt;<br>
&gt; &gt; Is it impossible to leverage PyQt&#39;s support for cooperative<br>
&gt; &gt; multi-inheritance in this case?<br>
&gt; &gt;<br>
&gt; &gt; I&#39;d like the class to be a QObject, so that I can emit signals from<br>
&gt; &gt; it, but at the same time a QRunnable so that I can run it on a<br>
&gt; &gt; QThreadPool. AFAIK this is possible from C++, but looks like it \
won&#39;t<br> &gt; &gt; work with PyQt?<br>
&gt;<br>
&gt; Correct - the usual restrictions on multiple inheritance of C++ classes.</p>
<p dir="ltr">Alright, thanks.</p>
<p dir="ltr">In the end I&#39;ve reworked the code so I don&#39;t even need the \
threading, but good to know.</p> <p dir="ltr">Elvis</p>
<p dir="ltr">&gt;<br>
&gt; Phil<br>
</p>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic