Event Handling and Signal-Slot Mechanism

BlueBird phil at freehackers.org
Mon Jan 19 12:03:09 EST 2009


On Jan 19, 4:10 am, Steven Woody <narkewo... at gmail.com> wrote:
> Hi,
>
> Python has Signal-Slot mechanism,

Python does not have signal/slot mechanism. You are talking about the
Qt toolkit, which is initially a (nice) C++ toolkit, available also in
python via the PyQt wrapper.

Signal/slots were introduced by Qt to make C++ gui programming easier.
Signal/slots basically provides a very easy way to implement the
observer/consumer design pattern, with only 2 or 3 lines of code (as
opposed to one or two classes in java for example).

Python itself does not have signal/slots but the it's very easy to
emulate them using the Python language. In C++ however, it's tricky to
do signal/slots in pure C++ and this addition is one of the reason
that programming GUI in Qt is nice (personal opinion obviously).

To comne back to your question:

> why he still need another mechanism
> Event Handling?  

This is actually a Qt question: why have event handling for some
things, and signal/slot for some others ?

My opinion on the debate:
- signal/slot add an overhead of one class to every QObject class, and
3 method calls when emitting a signal (if I remember Qt documentation
correctly). For some real-time tasks, like repainting the screen,
every microseconds must be saved and sparing 3 method calls is a good
idea.
- since a GUI application is fundamentally an event driven system, the
event stuff has to be there anyway.
- signal/slot is very convenient for data exchange between widgets but
I think it would be overkill to use it everywhere. Event propagation
is a nice design as well.

Now, if you want to discuss this further, I suggest to go to Qt
interest ( http://lists.trolltech.com/qt-interest/ ) which is
dedicated to discussion around Qt.

cheers,

Philippe



More information about the Python-list mailing list