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

Eduardo Robles Elvira edulix at gmail.com
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
{
    Q_OBJECT

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

class B
    : public QObject
{
    Q_OBJECT

public:
    void tachan()
    {
        connect(this, SIGNAL(signalB()), new A(), SLOT(debugMe()));
        signalB();
    }

Q_SIGNALS:
    void signalB();
};

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

    B *b = new B();
    b->tachan();

    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.

Regards,
        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: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20080225/695ffa34/attachment.sig>


More information about the kde-core-devel mailing list