Results 1 to 2 of 2

Thread: in SLOT: determine which signal sent the signal?

  1. #1
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default in SLOT: determine which signal sent the signal?

    hello-

    I have a slot with the following code:

    Qt Code:
    1. QSlider *locSlider = qobject_cast<QSlider *>(sender());
    2. QButtonGroup *locBG = qobject_cast<QButtonGroup *>(sender());
    3.  
    4. if( QButtonGroup *locBG = qobject_cast<QButtonGroup *>(sender()) )
    5. { etc... }
    6.  
    7. if(locSlider == zXag[2])
    8. { etc.... }
    9.  
    10. if( (locSlider == NULL) && (locBG == NULL) )
    11. { etc... }
    To copy to clipboard, switch view to plain text mode 

    and 3 things connected to the slot: a QSlider, a QButtonGroup, and a custom signal, customSG. This works: if customSG makes the call, the appropriate conditional is entered (i.e. when locSlider and locBG are NULL). But... what if I want to connect two Signals? How can I determine which Signal made the call? Or in such situations, should I just code a 2nd SLOT?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: in SLOT: determine which signal sent the signal?

    It looks like you need more than one slot.

    Slots should be implemented in such way that they don't need to know what signal was sent and who sent it. Otherwise you get tight coupling. "Do X or Y, depending on what happened" isn't a good way to code a slot. You should create two separate slots: "do X" and "do Y". This way you can decide what actions should be taken simply by establishing connections.

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

    vonCZ (8th November 2007)

Similar Threads

  1. signal and slot across threads having event loop
    By travis in forum Qt Programming
    Replies: 6
    Last Post: 5th November 2007, 23:56
  2. Replies: 2
    Last Post: 16th August 2007, 00:20
  3. signal not getting communicated to slot
    By quickNitin in forum Qt Programming
    Replies: 17
    Last Post: 2nd June 2006, 04:56
  4. Manually send signal to slot
    By donmorr in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2006, 15:03
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.