Event Handling and Signal-Slot Mechanism

S

Steven Woody

Hi,

Python has Signal-Slot mechanism, why he still need another mechanism
Event Handling? And, in some cases, it seems only Event Handling
mechanism is available, for example closeEvent(). For what case and
for what reason, the python think Signal Slot is not enough and will
not work?

Thanks.
 
B

BlueBird

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
 
S

Steven Woody

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:


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

So much thanks, Philippe!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top