summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas McGuire <thomas.mcguire.qnx@kdab.com>2012-09-28 10:57:42 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-12 00:19:36 (GMT)
commit5fa395cfd5ac2dd82a4d1f64dd6e72990f0e2be0 (patch)
treed789ab5f452722907aef45e79a1c0bdb9d61b390
parent79cbdb503aec471cfb1dfcc7b36867490e4ca7ee (diff)
downloadQt-5fa395cfd5ac2dd82a4d1f64dd6e72990f0e2be0.zip
Qt-5fa395cfd5ac2dd82a4d1f64dd6e72990f0e2be0.tar.gz
Qt-5fa395cfd5ac2dd82a4d1f64dd6e72990f0e2be0.tar.bz2
Fix QObject::receivers() within connectNotify()
The receiver count needs to be correct in connectNotify() to be compatible with ordinary connections. Fix this and add test. This is a backport of qtdeclarative commit b1c6e095404ccb7788e6b12fff692c71f4900815 Change-Id: Ic3145a536c928eccfcc29b4d010a526135b654b0 Reviewed-by: Alan Alpert <416365416c@gmail.com>
-rw-r--r--src/declarative/qml/qdeclarativeboundsignal.cpp1
-rw-r--r--src/declarative/qml/qdeclarativeproperty.cpp7
-rw-r--r--tests/auto/declarative/qdeclarativenotifier/tst_qdeclarativenotifier.cpp2
3 files changed, 9 insertions, 1 deletions
diff --git a/src/declarative/qml/qdeclarativeboundsignal.cpp b/src/declarative/qml/qdeclarativeboundsignal.cpp
index 9bccb42..720c725 100644
--- a/src/declarative/qml/qdeclarativeboundsignal.cpp
+++ b/src/declarative/qml/qdeclarativeboundsignal.cpp
@@ -136,6 +136,7 @@ QDeclarativeBoundSignal::~QDeclarativeBoundSignal()
void QDeclarativeBoundSignal::disconnect()
{
+ QMetaObject::disconnect(m_scope, m_signal.methodIndex(), this, evaluateIdx);
QObjectPrivate * const priv = QObjectPrivate::get(m_scope);
QVarLengthArray<char> signalSignature;
QObjectPrivate::signalSignature(m_signal, &signalSignature);
diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp
index ce4122a..6ad94c2 100644
--- a/src/declarative/qml/qdeclarativeproperty.cpp
+++ b/src/declarative/qml/qdeclarativeproperty.cpp
@@ -1632,13 +1632,18 @@ bool QDeclarativePropertyPrivate::connect(QObject *sender, int signal_index,
flush_vme_signal(sender, signal_index);
flush_vme_signal(receiver, method_index);
+ const bool result =
+ QMetaObject::connect(sender, signal_index, receiver, method_index, type, types);
+
+ // connectNotify() needs to be called after the actual connect, as otherwise QObject::receivers()
+ // would return the wrong result inside connectNotify().
const QMetaMethod signal = sender->metaObject()->method(signal_index);
QObjectPrivate * const senderPriv = QObjectPrivate::get(sender);
QVarLengthArray<char> signalSignature;
QObjectPrivate::signalSignature(signal, &signalSignature);
senderPriv->connectNotify(signalSignature.constData());
- return QMetaObject::connect(sender, signal_index, receiver, method_index, type, types);
+ return result;
}
/*!
diff --git a/tests/auto/declarative/qdeclarativenotifier/tst_qdeclarativenotifier.cpp b/tests/auto/declarative/qdeclarativenotifier/tst_qdeclarativenotifier.cpp
index 07283f9..ae27ae3 100644
--- a/tests/auto/declarative/qdeclarativenotifier/tst_qdeclarativenotifier.cpp
+++ b/tests/auto/declarative/qdeclarativenotifier/tst_qdeclarativenotifier.cpp
@@ -114,6 +114,7 @@ protected:
if (signalName == SIGNAL(compiledBindingPropSharedChanged())) compiledBindingPropSharedConnections++;
if (signalName == SIGNAL(boundSignal())) boundSignalConnections++;
if (signalName == SIGNAL(unusedSignal())) unusedSignalConnections++;
+ verifyReceiverCount();
//qDebug() << Q_FUNC_INFO << this << signalName;
}
@@ -129,6 +130,7 @@ protected:
if (signalName == SIGNAL(compiledBindingPropSharedChanged())) compiledBindingPropSharedConnections--;
if (signalName == SIGNAL(boundSignal())) boundSignalConnections--;
if (signalName == SIGNAL(unusedSignal())) unusedSignalConnections--;
+ verifyReceiverCount();
//qDebug() << Q_FUNC_INFO << this << signalName;
}