[PyQt] the mechanism behind qt signal and slot

Von vontio at gmail.com
Mon Sep 20 04:27:15 BST 2010


Many thanks,Andreas.

On Mon, Sep 20, 2010 at 2:09 AM, Andreas Pakulat <apaku at gmx.de> wrote:

> On 19.09.10 18:15:15, Von wrote:
> > Hi,Algis,many thanks for all these informations.
> > At first I thought QtCore.QtObject.connect as static method of
> > QtObject,later I realized that,this is py style of calling super method.
> > That's why I asked question (3).
> > The document of pyqt says "The code (or component) that emits the signal
> > does not know or care if the signal is being used."
> > In my head,the implementation of signal and slot is an observer pattern.
> > Pseudo-code:
> > def connect(source,signal,slot):
> >     if(not source.slots[signal]):
> >         source.slots[signal] = []
> >     source.slots[signal].append(slot)
> >
> > def emit(signal,param):
> >     for slot in self.slots[signal]:
> >         slot(param)
> > I am wondering why signal does not know what slots bind with it?
>
> That pseudo code is pretty close to reality, except that (in C++ Qt)
> emit is just a macro and the for slot in slots-stuff is in the
> moc-generated code. So the signal does know which slots are connected,
> but whoever call emit mysignal doesn't know and doesn't care. Thats the
> point of loosely coupled objects and encapsulation. The code that emits
> the signal always does so, no matter wether there are any connected
> slots or not. So the for-loop might not run its body even once, but the
> 'emission' is always done. Thats what is meant with 'the code that emits
> the signal doesn't know or care if the signal is being used'
>
> Andreas
>
> --
> Your step will soil many countries.
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100920/27eebe8a/attachment-0001.html>


More information about the PyQt mailing list