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

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:

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

equivalent to the non-static overloaded function

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

Disconnect everything connected to a specific signal:

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

equivalent to the non-static overloaded function

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

Disconnect a specific receiver:

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

equivalent to the non-static overloaded function

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

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 2576 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(), TabWidget::currentChanged(), Q3Signal::disconnect(), QProxyModel::disconnectFromModel(), QtCursorEditorFactory::disconnectPropertyManager(), QtCheckBoxFactory::disconnectPropertyManager(), QtSliderFactory::disconnectPropertyManager(), QtTimeEditFactory::disconnectPropertyManager(), QtSpinBoxFactory::disconnectPropertyManager(), QtDateTimeEditFactory::disconnectPropertyManager(), QtEnumEditorFactory::disconnectPropertyManager(), QtFontEditorFactory::disconnectPropertyManager(), QtDateEditFactory::disconnectPropertyManager(), QtLineEditFactory::disconnectPropertyManager(), QtKeySequenceEditorFactory::disconnectPropertyManager(), QtDoubleSpinBoxFactory::disconnectPropertyManager(), QtCharEditorFactory::disconnectPropertyManager(), QtColorEditorFactory::disconnectPropertyManager(), QtScrollBarFactory::disconnectPropertyManager(), Q3IconView::doAutoScroll(), QPrintDialog::done(), QPrintPreviewDialog::done(), QAbstractPageSetupDialog::done(), QFontDialog::done(), QColorDialog::done(), QInputDialog::done(), QFileDialog::done(), QLineEdit::focusOutEvent(), QSyntaxHighlighter::rehighlight(), QWidgetAction::releaseWidget(), QObjectCleanupHandler::remove(), QActionGroup::removeAction(), QDialogButtonBox::removeButton(), Q3MainWindow::removeDockWindow(), Q3Action::removeFrom(), QToolBox::removeItem(), QtAbstractEditorFactory< QtStringPropertyManager >::removePropertyManager(), HistoryFilterModel::removeRows(), QUndoGroup::setActiveStack(), Phonon::VolumeSlider::setAudioOutput(), QDBusAbstractAdaptor::setAutoRelaySignals(), QScriptEngineDebugger::setAutoShowStandardWindow(), Q3CanvasView::setCanvas(), Q3ListView::setColumnWidth(), QLineEdit::setCompleter(), TextEdit::setCompleter(), QSyntaxHighlighter::setDocument(), QUndoView::setGroup(), QAbstractItemView::setItemDelegate(), QDataWidgetMapper::setItemDelegate(), QAbstractItemView::setItemDelegateForColumn(), QAbstractItemView::setItemDelegateForRow(), Phonon::SeekSlider::setMediaObject(), 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(), QAbstractProxyModel::setSourceModel(), HistoryFilterModel::setSourceModel(), Q3NetworkProtocol::setUrl(), ConclusionPage::setVisible(), Q3DataTable::sliderPressed(), Q3ActionGroup::~Q3ActionGroup(), QComboBox::~QComboBox(), QGraphicsProxyWidget::~QGraphicsProxyWidget(), 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;
    }

    const char *signal_arg = signal;
    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;
    const char *method_arg = method;
    int membcode = -1;
    bool method_found = false;
    if (method) {
        method_name = QMetaObject::normalizedSignature(method);
        method = method_name;
        membcode = extract_code(method);
        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(sender, signal_arg, "disconnect");
        err_info_about_objects("disconnect", sender, receiver);
    } else if (method && !method_found) {
        err_method_notfound(receiver, method_arg, "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