diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 5e8a97cdc0..e714168e16 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -4711,10 +4711,14 @@ bool QObject::disconnectImpl(const QObject *sender, void **signal, const QObject int signal_index = -1; if (signal) { void *args[] = { &signal_index, signal }; - senderMetaObject->static_metacall(QMetaObject::IndexOfMethod, 0, args); - if (signal_index < 0 || signal_index >= QMetaObjectPrivate::get(senderMetaObject)->signalCount) { - qWarning("QObject::disconnect: signal not found in %s", senderMetaObject->className()); - return false; + for (; senderMetaObject && signal_index < 0; senderMetaObject = senderMetaObject->superClass()) { + senderMetaObject->static_metacall(QMetaObject::IndexOfMethod, 0, args); + if (signal_index >= 0 && signal_index < QMetaObjectPrivate::get(senderMetaObject)->signalCount) + break; + } + if (!senderMetaObject) { + qWarning("QObject::disconnect: signal not found in %s", sender->metaObject()->className()); + return QMetaObject::Connection(0); } signal_index += QMetaObjectPrivate::signalOffset(senderMetaObject); } diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 1c0a495116..46f034ac84 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -6169,6 +6169,18 @@ void tst_QObject::connectBase() QCOMPARE( r1.count_slot1, 1 ); QCOMPARE( r1.count_slot2, 1 ); QCOMPARE( r1.count_slot3, 1 ); + + QVERIFY( QObject::disconnect( &sub, &SubSender::signal1 , &r1, &ReceiverObject::slot1 ) ); + QVERIFY( QObject::disconnect( &sub, static_cast(&SubSender::signal2) , &r1, &ReceiverObject::slot2 ) ); + QVERIFY( QObject::disconnect( &sub, static_cast(&SubSender::signal3) , &r1, &ReceiverObject::slot3 ) ); + + sub.emitSignal1(); + sub.emitSignal2(); + sub.emitSignal3(); + + QCOMPARE( r1.count_slot1, 1 ); + QCOMPARE( r1.count_slot2, 1 ); + QCOMPARE( r1.count_slot3, 1 ); } struct QmlReceiver : public QtPrivate::QSlotObjectBase