PDA

View Full Version : who sent the SIGNAL?



drhex
3rd August 2006, 22:24
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)

jacek
3rd August 2006, 22:34
QObject::sender()

lum
4th August 2006, 11:05
...
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.
...