Signals and Slots - Summerfield - what exactly is a signal?
Michael Torrie <torriem at gmail.com>:
> Basically a signal emission is a call to the main loop that indicates
> that an event has occurred, and then the main loop sees if there are
> any registered callbacks that want to be notified of this event, and
> if so it calls them, letting them execute. This is how event-driven
> programming works. The concept of signals and slots is very similar to
> explicit registering of callbacks in function. It differs only in
I would express it as just saying that the Qt developers appropriated
the word "signal" for what is simply a callback.
Years back I took a brief loook at Qt. I had heard that one of their
great selling points was that they did C++. At the time, C++ was my
bread and butter, and I had been baffled at how bad C++ was at
expressing such a basic thing as callbacks.
Turns out Qt didn't do callbacks using C++. Instead they specified a
sort of macro language to express callbacks and offered what was known
as a "metacompiler" that converted those macros into real C++.
It was a big disappointment both with respect to C++ and Qt.
Now, the Standard Template Library offered elaborate macros (aka functor
templates) that allowed you to express callbacks with zero, one or two
arguments (in a cumbersome way). Boost, a famous C++ class library,
added functor support to three, four, five, six, seven, eight, nine,
and--hear this!--TEN arguments.
All this nonsense because it hadn't occurred to Bjarne Stroustrup to
define so-called method pointers in a sane manner. It was left to
another Dane, Anders Hejlsberg, to demonstrate how they ought to have
been defined, namely, as delegates (as in Delphi and C#). Unfortunately,
it was too late for C++.
Now, I'm hearing C++ supports proper closures: <URL:
http://en.cppreference.com/w/cpp/language/lambda>. I wonder if Qt would
eventually migrate to them.
At any rate, Python never had to come up with such tricks for callbacks.
Python's closure syntax is maybe the most natural there is. Too bad if
PyQt confuses Python programmers with "signals" and "slots" when they
are simply methods.