[Qt-interest] Signal chaining

Rainer Wiesenfarth Rainer.Wiesenfarth at inpho.de
Mon Mar 29 15:15:17 CEST 2010


From: Mandeep Sandhu
> 
> On Mon, Mar 29, 2010 at 5:43 PM, Andreas Pakulat <apaku at gmx.de> wrote:
> >
> > No you don't. You only need A and C visible in B, which can 
> then make the
> > connection. Thats another nice thing about Qt's signal/slots you can
> 
> Right. But I didn't want to make A visible in B, since all these
> sub-level classes are helper classes and really shouldn't bother about
> who's calling.

I think it is possible with the visibility you would like if you do it like
this (the //LOOK HERE comments indicate the important parts):

===== c.h =====

class C : public QObject
{
    Q_OBJECT

public:

    ...
    
signals:

    void originalSignal ();

    ...
};

===== b.h =====

class C;

class B : public QObject
{
    Q_OBJECT

public:

    B ();
    ...

signals:

    void forwardedSignal ();

    ...

private:

    C   *m_pC;
};

===== b.cpp =====

#include <c.h>

B::B ()
    : m_pC (new C)
{
    //LOOK HERE:
    // forward the signal of the (hidden) member to the
    // application
    connect (m_pC, SIGNAL(originalSignal())
        , this, SIGNAL(forwardedSignal()));
    ...
}

===== a.h =====

class B;

class A : public Q_OBJECT
{
    Q_OBJECT

public:

    A ();
    ...

public slots:

    void finalAction ();

    ...

private:

    B   *m_pB;
};

===== a.cpp ====

#include <b.h>

A::A ()
    : m_pB (new B)
{
    //LOOK HERE:
    // connect to the forwarded signal without knowledge
    // on its originating class
    connect (m_pB, SIGNAL(forwardedSignal())
        , this, SLOT(finalAction()));
    ...
}

void A::finalAction ()
{
    ...
}

Best Regards / Mit freundlichen Grüßen
Rainer Wiesenfarth

-- 
INPHO GmbH * Smaragdweg 1 * 70174 Stuttgart * Germany
phone: +49 711 2288 10 * fax: +49 711 2288 111 * web: www.inpho.de
place of business: Stuttgart * managing director: Johannes Saile
commercial register: Stuttgart, HRB 9586
Leader in Photogrammetry and Digital Surface Modelling
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 6878 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100329/a21eef54/attachment.bin 


More information about the Qt-interest-old mailing list