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

bool QObject::disconnect ( const QObject sender,
const char *  signal,
const QObject receiver,
const char *  method 
) [static, inherited]

Disconnects signal in object sender from method in object receiver. Returns true if the connection is successfully broken; otherwise returns false.

A signal-slot connection is removed when either of the objects involved are destroyed.

disconnect() is typically used in three ways, as the following examples demonstrate. 1 Disconnect everything connected to an object's signals:

       disconnect(myObject, 0, 0, 0);

equivalent to the non-static overloaded function

       myObject->disconnect();

Disconnect everything connected to a specific signal:

       disconnect(myObject, SIGNAL(mySignal()), 0, 0);

equivalent to the non-static overloaded function

       myObject->disconnect(SIGNAL(mySignal()));

Disconnect a specific receiver:

       disconnect(myObject, 0, myReceiver, 0);

equivalent to the non-static overloaded function

       myObject->disconnect(myReceiver);

0 may be used as a wildcard, meaning "any signal", "any receiving object", or "any slot in the receiving object", respectively.

The sender may never be 0. (You cannot disconnect signals from more than one object in a single call.)

If signal is 0, it disconnects receiver and method from any signal. If not, only the specified signal is disconnected.

If receiver is 0, it disconnects anything connected to signal. If not, slots in objects other than receiver are not disconnected.

If method is 0, it disconnects anything that is connected to receiver. If not, only slots named method will be disconnected, and all other slots are left alone. The method must be 0 if receiver is left out, so you cannot disconnect a specifically-named slot on all objects.

See also:
connect()

Definition at line 2687 of file qobject.cpp.

References QMetaObject::disconnect(), QObject::disconnectNotify(), QMetaObject::indexOfMethod(), QMetaObject::indexOfSignal(), QMetaObject::normalizedSignature(), and QMetaObject::superClass().

Referenced by QMenuBar::actionEvent(), QMenu::actionEvent(), QToolButton::actionEvent(), QMainWindow::addToolBar(), Q3TextEdit::checkOptimMode(), QDialogButtonBox::clear(), Q3TextEdit::clipboardChanged(), Q3TextEdit::contentsContextMenuEvent(), Q3ListView::contentsMouseMoveEvent(), Q3IconView::contentsMouseReleaseEvent(), Q3UrlOperator::continueCopy(), Q3Signal::disconnect(), QProxyModel::disconnectFromModel(), Q3IconView::doAutoScroll(), QLineEdit::focusOutEvent(), QSyntaxHighlighter::rehighlight(), QWidgetAction::releaseWidget(), Q3ButtonGroup::remove(), QObjectCleanupHandler::remove(), QActionGroup::removeAction(), QDialogButtonBox::removeButton(), Q3MainWindow::removeDockWindow(), Q3Action::removeFrom(), QToolBox::removeItem(), QtWindowListMenu::removeWindow(), QUndoGroup::setActiveStack(), QDBusAbstractAdaptor::setAutoRelaySignals(), Q3CanvasView::setCanvas(), Q3ListView::setColumnWidth(), QLineEdit::setCompleter(), QSyntaxHighlighter::setDocument(), QUndoView::setGroup(), QAbstractItemView::setItemDelegate(), QDataWidgetMapper::setItemDelegate(), QAbstractItemView::setItemDelegateForColumn(), QAbstractItemView::setItemDelegateForRow(), QPushButton::setMenu(), QComboBox::setModel(), QHeaderView::setModel(), QTreeView::setModel(), QDataWidgetMapper::setModel(), QAbstractItemView::setModel(), QCompleter::setPopup(), QFileDialog::setProxyModel(), QGraphicsView::setScene(), QAbstractItemView::setSelectionModel(), QTreeView::setSelectionModel(), Q3DataTable::setSize(), QSortFilterProxyModel::setSourceModel(), Q3NetworkProtocol::setUrl(), Q3DataTable::sliderPressed(), Q3ActionGroup::~Q3ActionGroup(), QComboBox::~QComboBox(), QItemSelectionModel::~QItemSelectionModel(), and QWidgetAction::~QWidgetAction().

{
    if (sender == 0 || (receiver == 0 && method != 0)) {
        qWarning("Object::disconnect: Unexpected null parameter");
        return false;
    }

    {
        const void *cbdata[] = { sender, signal, receiver, method };
        if (QInternal::activateCallbacks(QInternal::DisconnectCallback, (void **) cbdata))
            return true;
    }

    QByteArray signal_name;
    bool signal_found = false;
    if (signal) {
        signal_name = QMetaObject::normalizedSignature(signal);
        signal = signal_name;
        if (!check_signal_macro(sender, signal, "disconnect", "unbind"))
            return false;
        signal++; // skip code
    }

    QByteArray method_name;
    int membcode = -1;
    bool method_found = false;
    if (method) {
        method_name = QMetaObject::normalizedSignature(method);
        method = method_name;
        membcode = method[0] - '0';
        if (!check_method_code(membcode, receiver, method, "disconnect"))
            return false;
        method++; // skip code
    }

    /* We now iterate through all the sender's and receiver's meta
     * objects in order to also disconnect possibly shadowed signals
     * and slots with the same signature.
    */
    bool res = false;
    const QMetaObject *smeta = sender->metaObject();
    do {
        int signal_index = -1;
        if (signal) {
            signal_index = smeta->indexOfSignal(signal);
            if (signal_index < smeta->methodOffset())
                continue;
            signal_found = true;
        }

        if (!method) {
            res |= QMetaObject::disconnect(sender, signal_index, receiver, -1);
        } else {
            const QMetaObject *rmeta = receiver->metaObject();
            do {
                int method_index = rmeta->indexOfMethod(method);
                if (method_index >= 0)
                    while (method_index < rmeta->methodOffset())
                            rmeta = rmeta->superClass();
                if (method_index < 0)
                    break;
                res |= QMetaObject::disconnect(sender, signal_index, receiver, method_index);
                method_found = true;
            } while ((rmeta = rmeta->superClass()));
        }
    } while (signal && (smeta = smeta->superClass()));

    if (signal && !signal_found) {
        err_method_notfound(QSIGNAL_CODE, sender, signal, "disconnect");
        err_info_about_objects("disconnect", sender, receiver);
    } else if (method && !method_found) {
        err_method_notfound(membcode, receiver, method, "disconnect");
        err_info_about_objects("disconnect", sender, receiver);
    }
    if (res)
        const_cast<QObject*>(sender)->disconnectNotify(signal ? (signal - 1) : 0);
    return res;
}


Generated by  Doxygen 1.6.0   Back to index