[PyQt] the mechanism behind qt signal and slot
Andreas Pakulat
apaku at gmx.de
Sun Sep 19 10:54:54 BST 2010
On 19.09.10 18:18:15, Algis Kabaila wrote:
> On Sunday 19 September 2010 17:41:59 Von wrote:
> > Hi,Algis,
> > I have looked through this chapter "Events, the Clipboard, and Drag and
> > Drop", and I couldn't find anything about signal/slot mechanism.
> >
> > Best Regards
>
> 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.
There can be indirect calls through events when using the
queued-connection (implicitly or explicitly), but even then the event
thats used is not propagated through the widget tree.
The object connecting the sender and receiver is often a composite
having both as children and hence its responsibility is usually to
delete both when they're not needed anymore. The Qt parent/child
hierarchy helps with this, so its a no-brainer for most people.
Thats all the Qt-level of signal/slots, I don't know how Phil
implemented the new-style-signal/slots but they also don't propagate
upwards in the widget-hierarchy.
Andreas
--
You look tired.
More information about the PyQt
mailing list