Signals: Is this the expected behaviour of connect() ?

Eduardo Robles Elvira edulix at
Mon Feb 25 07:46:36 GMT 2008

El Lunes 25 Febrero 2008, Thiago Macieira escribió:
> No.
> Signal to signal connection is allowed and part of the design.

Of course, I knew it. But that's not what I was talking about.. What you I 
normally do when connecting two signals is to trigger a signal of mine by 
conecting to it an external one, and not the other way around, which is the 
case here.

A similar thing happens when you connect a signal to a private one of another 
class, as Rafael Fernandez (ereslibre) noticed when I was discussing the 
signal triggering problem with him. This is the sample code:

// <code>
#include <QtCore/QDebug>
#include <QtCore/QObject>
#include <QtGui/QApplication>

class A
    : public QObject

private Q_SLOTS:
    void debugMe()
        qDebug() << "SIGNAL A WAS EMITTED";

class B
    : public QObject

    void tachan()
        connect(this, SIGNAL(signalB()), new A(), SLOT(debugMe()));

    void signalB();

int main(int argc, char **argv)
    QApplication app(argc, argv);

    B *b = new B();

    return app.exec();

#include "test.moc"
// </code>

The private slot A::debugMe() is executed, triggered by B::signalB(), even if 
B and A are not friend classes, so it's clear that in this case connect() 
doesn't take into accound if the scope is private/public.

        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...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <>

More information about the kde-core-devel mailing list