Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QObject * QObject::sender (  )  const [protected, inherited]

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.

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.
See also:

Definition at line 2189 of file qobject.cpp.

Referenced by Q3ButtonGroup::buttonClicked(), Q3ButtonGroup::buttonPressed(), Q3ButtonGroup::buttonReleased(), Q3ActionGroup::childActivated(), Q3ActionGroup::childDestroyed(), Q3ActionGroup::childToggled(), QSignalMapper::map(), Q3MainWindow::menuAboutToShow(), Q3ActionGroup::objectDestroyed(), Q3Action::objectDestroyed(), and Q3Action::showStatusText().

    Q_D(const QObject);
    QConnectionList * const list = ::connectionList();
    if (!list)
        return 0;

    QReadLocker locker(&list->lock);
    QConnectionList::Hash::const_iterator it = list->sendersHash.constFind(d->currentSender);
    const QConnectionList::Hash::const_iterator end = list->sendersHash.constEnd();

    // Return 0 if d->currentSender isn't in the senders hash (it has been destroyed?)
    if (it == end)
        return 0;

    // Only return d->currentSender if it's actually connected to "this"
    for (; it != end && it.key() == d->currentSender; ++it) {
        const int at = it.value();
        const QConnection &c = list->connections.at(at);

        if (c.receiver == this)
            return d->currentSender;

    return 0;

Generated by  Doxygen 1.6.0   Back to index