Signals and Slots - Summerfield - what exactly is a signal?
Steve D'Aprano wrote:
> On Sun, 6 Aug 2017 12:28 am, veek wrote:
>> 1. What exactly is a signal. In hardware, an interrupt can be viewed as a
>> signal and the voltage on a pin will suddenly jump to +5V as an indicator
>> that an interrupt has occurred. With Qt signals - if a widget-c++ code
>> has to 'signal' an event - what does it do?
> I don't know what Qt signals are.
> Unix signals are an interrupt mechanism used by Unix and Linux operating
> systems. Windows may support them as well. The "kill" system command sends
> signals to a specific running process, which will then jump to a specific
> piece of code. The command is called "kill" because the main use for this
> is to terminate processes.
> Python supports these signals:
>> As a consequence of not understanding the above..
>> 2. How do you connect a single signal to multiple slots? Do the
>> slots/methods get called one by one? or are they treated as independent
>> threads and run on different cores?
> What are slots?
>> 3. pg 130 of Summerfield
> What is Summerfield?
The book I'm reading is: Mark Summerfield - Rapid GUI Programming with
Python and Qt.
PyQt is a wrapper around the C++/Qt library and they have a Signal and Slot
mechanism for doing GUI/event-driven work - Qt doesn't have it.
Basically if you have a widget like QSpinBox it'll be rendered/drawn using a
C++ Qt library (which is fast).
Anyway, widgets support 'events' like mouse-over and click and they are
constantly generating events which are mostly ignored by the PyQt library
and discarded. However if you decide you want to handle an event then you
use PyQt's signal/slot mechanism: slot's a method and signal looks to be
basically a string.
def __init__(self, parent=None):
super(Form, self).__init__(parent) #init QWidget with parent is set
combo = QComboBox()
def combo_event_handler(self, i):
combo_event_handler's the slot.. it's just a python OR Qt method.
QComboBox() will result in a combo box being drawn when the app is started
app = QApplication()
then if I mouse over the widget it'll generate an 'event'/'signal'
and call the handler to process - event driven programming
"some_event()" is a string being passed to connect() and that's a function
signature that tells connect what types the handler expects.
combo_event_handler can be a Qt method in which case conversion occurs to
C++ data types but it can also be a python method and if you short ckt then
no conversion to C++ types occurs.