Signals: Is this the expected behaviour of connect() ?
Eduardo Robles Elvira
edulix at gmail.com
Sun Feb 24 22:53:42 GMT 2008
I myself have a quite twisted mind and like to find the boundaries of the
things in order to understand them. And doing some Konqueror programming I've
noticed an interesting Qt behaviour that can be shown with this sample code,
which ends up printing "SIGNAL A WAS EMITTED":
: public QObject
connect(this, SIGNAL(signalA()), SLOT(debugMe()));
qDebug() << "SIGNAL A WAS EMITTED";
: public QObject
connect(this, SIGNAL(signalB()), new A(), SIGNAL(signalA()));
int main(int argc, char **argv)
QApplication app(argc, argv);
B *b = new B();
This means that if you have a class A, I can trigger any signal of that class
from within any other class that links to an A object.
Intuitively, this shouldn't work. signalA() should only be triggered by a
given A class, or a friend class, or a parent class. That's the way I
understand it, anyway. Or understood, until now =).
And indeed, it seems that signals were designed somehow to be only triggered
by it's owner (and friends & parents). You cannot do emit new
A()->signalA(); inside B. It doesn't even compile because the signal
is "protected". But then, as the given code shows, connecting signalB() to
signalA() and triggering signalA(), works fine - so maybe this is a bug?
Eduardo Robles Elvira.
"The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all progress
depends on the unreasonable man." (George Bernard Shaw)
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 189 bytes
Desc: This is a digitally signed message part.
More information about the kde-core-devel