[Qt-interest] Signal chaining
Mandeep Sandhu
mandeepsandhu.chd at gmail.com
Mon Mar 29 15:26:04 CEST 2010
Thanks Rainer, this is what I've done currently! :)
Regards,
-mandeep
On Mon, Mar 29, 2010 at 6:45 PM, Rainer Wiesenfarth
<Rainer.Wiesenfarth at inpho.de> wrote:
>
> 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
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
More information about the Qt-interest-old
mailing list