aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2021-01-15 16:46:59 +0100
committerAndrei Golubev <andrei.golubev@qt.io>2021-01-21 08:38:50 +0100
commit90be89d771425044a84e9e79e4e668e065acc825 (patch)
tree0c8d90aed1efb03391b062fcffd16a33dc8f6c64 /src
parent3c6b913123856c3ef198e51b99bed5841bd81aaf (diff)
Use new QObjectPrivate connection mechanism in dynamic connections
Old API assumes sender == receiver, which results in wrong handling of connections when receiver is deleted: connection is not removed or notified elsehow as it's not really tied to a valid receiver Task-number: QTBUG-86368 Pick-to: 5.15 6.0 Change-Id: I0f3115f1b0f26cf353752ba2b8fd88e0f3bdd388 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index 08d0c6f40e..98d69b2f80 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -90,6 +90,7 @@
QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcBindingRemoval, "qt.qml.binding.removal", QtWarningMsg)
+Q_LOGGING_CATEGORY(lcObjectConnect, "qt.qml.object.connect", QtWarningMsg)
// The code in this file does not violate strict aliasing, but GCC thinks it does
// so turn off the warnings for us to have a clean build
@@ -1100,7 +1101,16 @@ ReturnedValue QObjectWrapper::method_connect(const FunctionObject *b, const Valu
QQmlPropertyPrivate::flushSignal(signalObject, propertyCache->methodIndexToSignalIndex(signalIndex));
}
}
- QObjectPrivate::connect(signalObject, signalIndex, slot, Qt::AutoConnection);
+
+ QPair<QObject *, int> functionData = QObjectMethod::extractQtMethod(f); // align with disconnect
+ if (QObject *receiver = functionData.first) {
+ QObjectPrivate::connect(signalObject, signalIndex, receiver, slot, Qt::AutoConnection);
+ } else {
+ qCInfo(lcObjectConnect,
+ "Could not find receiver of the connection, using sender as receiver. Disconnect "
+ "explicitly (or delete the sender) to make sure the connection is removed.");
+ QObjectPrivate::connect(signalObject, signalIndex, signalObject, slot, Qt::AutoConnection);
+ }
RETURN_UNDEFINED();
}
@@ -1151,7 +1161,13 @@ ReturnedValue QObjectWrapper::method_disconnect(const FunctionObject *b, const V
&functionData.second
};
- QObjectPrivate::disconnect(signalObject, signalIndex, reinterpret_cast<void**>(&a));
+ if (QObject *receiver = functionData.first) {
+ QObjectPrivate::disconnect(signalObject, signalIndex, receiver,
+ reinterpret_cast<void **>(&a));
+ } else {
+ QObjectPrivate::disconnect(signalObject, signalIndex, signalObject,
+ reinterpret_cast<void **>(&a));
+ }
RETURN_UNDEFINED();
}