Results 1 to 5 of 5

Thread: Finding which widget has triggered a slot

  1. #1
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    18
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Finding which widget has triggered a slot

    Hi,

    if I connect two QAbstractButton::clicked(bool) signals to a slot buttonsClicked(bool), is there a way to determine which button was clicked ?

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Finding which widget has triggered a slot


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

    ouekah (26th April 2010)

  4. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Finding which widget has triggered a slot

    and then you will need to cast it to the type you want..
    like in the slot :
    QPushButton *pSender = qobject_cast<QPushButton *>(sender());

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

    ouekah (26th April 2010)

  6. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Finding which widget has triggered a slot

    See also QSignalMapper!

  7. The following user says thank you to Lykurg for this useful post:

    ouekah (26th April 2010)

  8. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Finding which widget has triggered a slot

    With QSignalMapper being much more OO than ugly type casting of sender()

    The result can also be used in switch/case statements, as the return value is constant, so can make for more readable, more optimisable code.

  9. The following user says thank you to squidge for this useful post:

    ouekah (26th April 2010)

Similar Threads

  1. UI Builder Error: Finding/Adding A Slot
    By hkothari in forum Qt Tools
    Replies: 5
    Last Post: 20th April 2014, 13:41
  2. Replies: 1
    Last Post: 11th April 2010, 14:21
  3. Replies: 1
    Last Post: 7th December 2009, 18:49
  4. Capture the triggered event of MacWindowToolBarButtonHint
    By alexandersv in forum Qt Programming
    Replies: 0
    Last Post: 11th October 2009, 17:05
  5. Finding widget by name
    By mkarakaplan in forum Newbie
    Replies: 1
    Last Post: 9th December 2007, 17:38

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.