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

int QObject::receivers ( const char *  signal  )  const [protected, inherited]

Returns the number of receivers connected to the signal.

Since both slots and signals can be used as receivers for signals, and the same connections can be made many times, the number of receivers is the same as the number of connections made from this signal.

When calling this function, you can use the SIGNAL() macro to pass a specific signal:

doc/src/snippets/code/src_corelib_kernel_qobject.cpp 21

As the code snippet above illustrates, you can use this function to avoid emitting a signal that nobody listens to.

This function violates the object-oriented principle of modularity. However, it might be useful when you need to perform expensive initialization only if something is connected to a signal.

Definition at line 2284 of file qobject.cpp.

References QList< T >::at(), QList< T >::count(), QMetaObject::indexOfSignal(), and QMetaObject::normalizedSignature().

Referenced by Q3IconView::contentsContextMenuEvent(), Q3Table::contentsContextMenuEvent(), Q3ListBox::contentsContextMenuEvent(), Q3ListView::contentsContextMenuEvent(), and Q3Process::disconnectNotify().

    int receivers = 0;
    if (signal) {
        QByteArray signal_name = QMetaObject::normalizedSignature(signal);
        signal = signal_name;
#ifndef QT_NO_DEBUG
        if (!check_signal_macro(this, signal, "receivers", "bind"))
            return 0;
        signal++; // skip code
        const QMetaObject *smeta = this->metaObject();
        int signal_index = smeta->indexOfSignal(signal);
        if (signal_index < 0) {
#ifndef QT_NO_DEBUG
            err_method_notfound(this, signal-1, "receivers");
            return false;

        Q_D(const QObject);
        QMutexLocker locker(&d->threadData->mutex);
        if (d->connectionLists) {
            if (signal_index < d->connectionLists->count()) {
                const QObjectPrivate::ConnectionList &connectionList =
                for (int i = 0; i < connectionList.count(); ++i) {
                    const QObjectPrivate::Connection &c = connectionList.at(i);
                    receivers += c.receiver ? 1 : 0;
    return receivers;

Generated by  Doxygen 1.6.0   Back to index