Results 1 to 4 of 4

Thread: signal forwarding

  1. #1
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default signal forwarding

    Hi,

    I have three Objects A,B,C. A has access to B and B has access to C. This is not(!) vice versa, so C does not now anything from B and B does not know A.

    Now C emits "signal_C" and I want A to call a slot. Currently I connect "signal_C" with "slot_B". "slot_B" emits "signal_B", which is conected with "slot_A".

    Is there a possibility to make this a bit easier? Can B "forward" "signal_C" somehow? Like "on receiving signal_C emit signal_B"? Or is it already best practice wih "slot_B" emitting "signal_B"?

    I hope, this was not too confusing
    Felix

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: signal forwarding

    Can B "forward" "signal_C" somehow? Like "on receiving signal_C emit signal_B"
    Yes, you can connect signals to signals.
    http://doc.trolltech.com/4.7/signalsandslots.html
    It is even possible to connect a signal directly to another signal. (This will emit the second signal immediately whenever the first is emitted.)
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    FelixB (27th January 2011)

  4. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: signal forwarding

    Yes you can connect signal to another signal (link to documentation)
    Also the objects "live" in the same time, so you can directly connect signals and slot from outside of all of them (from the scope that include them)
    Qt Code:
    1. A *prtA = new A;
    2. B *ptrB = new B;
    3. C *ptrC = new C;
    4.  
    5. connect(ptrC, SIGNAL(signal_fromC()), ptrA, SLOT(slot_fromA()) );
    6. //if you are in main or outside other QObject derived class you just need to use the static connect, like this:
    7. //QObject::connect(ptrC, SIGNAL(signal_fromC()), ptrA, SLOT(slot_fromA()) );
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to Zlatomir for this useful post:

    FelixB (27th January 2011)

  6. #4
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signal forwarding

    Quote Originally Posted by high_flyer View Post
    Yes, you can connect signals to signals.
    Thank you, that's the perfect solution! Since this is just a matter of "documentation-reading", I'd better posted in the newbie-section

    Quote Originally Posted by Zlatomir View Post
    Also the objects "live" in the same time, so you can directly connect signals and slot from outside of all of them (from the scope that include them)
    of course, but that is not possible with my code structure. A is a framework, B an extension wich can be used within the framework and C is a dialog. I don't want the extension to have any information about the framework. Also, I don't want to add a pointer to the dialog to the public interface of the extension. There is no context which has access to the framework and to the dialog. So, the signal-signal-connection is a really nice solution.

Similar Threads

  1. OpenGL shaders and x11 forwarding
    By Wali in forum Qt Programming
    Replies: 0
    Last Post: 2nd November 2010, 21:38
  2. Connect signal/signal in Qt Designer
    By jlemaitre in forum Newbie
    Replies: 1
    Last Post: 22nd September 2010, 15:53
  3. signal mapping on pushbutton signal clicked
    By wagmare in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 07:54
  4. Replies: 6
    Last Post: 9th September 2008, 20:43
  5. Forwarding mouse events to another widget.
    By yogeshm02 in forum Qt Programming
    Replies: 8
    Last Post: 28th February 2006, 13:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.