Results 1 to 7 of 7

Thread: how can I know which object caused a specific event ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    3
    Thanked 65 Times in 59 Posts

    Default Re: how can I know which object caused a specific event ?

    Each handler (the "slot" procedure] can call sender() and get a pointer to the object which emitted the just processed signal. sender() returns a QObject * which you dynamic_cast to the real sender class (for example, QSlider). Comparing the pointer to addresses of the possible senders, you get the object which signal is processed. Note: calling sender() outside a handler (for example, in a procedure called by the handler - this is "outside, too) returns nullptr.

  2. The following user says thank you to Radek for this useful post:

    Hossein (21st October 2015)

Similar Threads

  1. Pass event (QWheelEvent) to a specific widget
    By stefanadelbert in forum Qt Programming
    Replies: 3
    Last Post: 5th May 2021, 03:10
  2. How to know the signal which caused a qstate transition
    By ClintEastwood in forum Qt Programming
    Replies: 6
    Last Post: 24th April 2013, 15:27
  3. Style3sheet problem, QTreeView for specific object
    By hubbobubbo in forum Qt Programming
    Replies: 2
    Last Post: 11th February 2010, 21:15
  4. Signal to specific object slot
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 27th December 2007, 15:51
  5. Crash caused by QVariant (mis)use
    By mclark in forum Newbie
    Replies: 2
    Last Post: 31st October 2006, 15:05

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.