[PyQt] the mechanism behind qt signal and slot

Andreas Pakulat apaku at gmx.de
Sun Sep 19 19:03:44 BST 2010


On 19.09.10 20:58:56, Algis Kabaila wrote:
> On Sunday 19 September 2010 19:54:54 Andreas Pakulat wrote:
> 
> > > Ch 10 does not talk about Signals-Slots directly, but it tells the
> > > details about the lower level events.  It is the same and one mechanism
> > > as Signals- Slots, it is just that it is looked  at from a different
> > > perspective. I think that usually the "signal" is caught by the "slot"
> > > and acted on it as required. OTH, if the signal is not caught by a
> > > "slot" it travels up the widget tree to the very top level widget and if
> > > it is not caught there, it is simply dropped (ignored).
> > 
> > No thats completely wrong. Signal/Slots are a direct connection between
> > emitter and receiver, there's no propagation 'upwards'. In fact most of
> > the time its a direct function call from the signal-function into the
> > slot.
> > 
> > It all works (at least on the pure-Qt level) through the
> > meta-object-code generated by moc. That one generates the code for the
> > signal-functions which use the Metaobject system to find all the slots
> > connected to the signal and call the slots directly.
> >
>  
> That's true, but what happens if the slot does not handle the signal?

This cannot happen. A signal-slot connection is a direct (or indirect)
function call. So if you emit a signal _all_ connected slots will be
executed, always (unless you block signal emission). 

> Why it may not handle it, I have no idea.  May be a programming
> mistake or whatever.  I seem to recall statement that if the signal is
> NOT handled, then the signal propagates in the tree up to the root.

This is the case only for events, for an event the receiver can decide
to accept it or not. If he doesn't accept it the event-propagation
mechanism is going to give its parent a chance to handle it until there
is no parent anymore at which point it'll be thrown away too.

Again, all of this is about the signals/slots as implemented by Qt, I
don't know the new signal/slot mechanisms in PyQt, but I doubt that Phil
deviated from the existing scheme that much that suddenly
signal-emission is similar to event-sending. 

Andreas

-- 
This life is yours.  Some of it was given to you; the rest, you made yourself.


More information about the PyQt mailing list