Results 1 to 3 of 3

Thread: who sent the SIGNAL?

  1. #1
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default who sent the SIGNAL?

    Hi,

    In a SLOT, is there a way to aquire a pointer to the object that emitted the signal?

    (Let's say several similar object are all connected to the same slot via one of QT's standard signals, and the slot wants to ask the emitting object about the value of some of its properies that was not among the arguments for the SIGNAL)

  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: who sent the SIGNAL?


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

    drhex (4th August 2006)

  4. #3
    Join Date
    Apr 2006
    Posts
    12
    Thanks
    3
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: who sent the SIGNAL?

    ...
    const QObject * QObject::sender () [protected]
    Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. The pointer is valid only during the execution of the slot that calls this function.
    The pointer returned by this function becomes invalid if the sender is destroyed, or if the slot is disconnected from the sender's signal.

    Warning: This function violates the object-oriented principle of modularity. However, getting access to the sender might be useful when many signals are connected to a single slot. The sender is undefined if the slot is called as a normal C++ function.
    ...

Similar Threads

  1. Replies: 2
    Last Post: 17th May 2006, 21:01
  2. QSortFilterProxyModel signal and selection confusion
    By pascal123 in forum Qt Programming
    Replies: 1
    Last Post: 1st April 2006, 16:25
  3. no such signal QListBox::currentChanged()
    By jopie bakker in forum Newbie
    Replies: 2
    Last Post: 2nd March 2006, 15:17
  4. send signal from QCombobox
    By raphaelf in forum Qt Programming
    Replies: 22
    Last Post: 28th February 2006, 14:18
  5. No such signal...
    By chaimar in forum Qt Programming
    Replies: 12
    Last Post: 24th January 2006, 22:33

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.