Event Handling and Signal-Slot Mechanism

Steven Woody narkewoody at gmail.com
Tue Jan 20 03:33:21 CET 2009


On Tue, Jan 20, 2009 at 1:03 AM, BlueBird <phil at freehackers.org> wrote:
> 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>

So much thanks, Philippe!



More information about the Python-list mailing list