diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-06-18 14:23:23 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-06-24 11:48:49 +0200 |
| commit | 7ac8c016bf0e57cd0eec7d61995e622dc2d2184b (patch) | |
| tree | b8bc1fc41779f83a594e569a8dad41cf550738bd /sources/pyside6/libpyside | |
| parent | d326e40e8c52c9f74b6baa0d6f7f9a54ded0172a (diff) | |
libpyside: Add explanatory comment about methods
Pick-to: 6.7
Change-Id: I0731c9c02de928dcdf268f5fc773148363b9a8fe
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/pyside6/libpyside')
| -rw-r--r-- | sources/pyside6/libpyside/globalreceiverv2.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/sources/pyside6/libpyside/globalreceiverv2.cpp b/sources/pyside6/libpyside/globalreceiverv2.cpp index 7bb1a7b7f..9610065f1 100644 --- a/sources/pyside6/libpyside/globalreceiverv2.cpp +++ b/sources/pyside6/libpyside/globalreceiverv2.cpp @@ -85,12 +85,16 @@ DynamicSlotDataV2::DynamicSlotDataV2(PyObject *callback, GlobalReceiverV2 *paren if (PyMethod_Check(callback)) { m_isMethod = true; - // To avoid increment instance reference keep the callback information + // A method given by "signal.connect(foo.method)" is a temporarily created + // callable/partial function where self is bound as a first parameter. + // It can be split into self and the function. Keeping a reference on + // the callable itself would prevent object deletion. Instead, keep a + // reference on the function and listen for destruction of the object + // using a weak reference with notification. m_callback = PyMethod_GET_FUNCTION(callback); Py_INCREF(m_callback); m_pythonSelf = PyMethod_GET_SELF(callback); - //monitor class from method lifetime m_weakRef = WeakRef::create(m_pythonSelf, DynamicSlotDataV2::onCallbackDestroyed, this); } else if (PySide::isCompiledMethod(callback)) { // PYSIDE-1523: PyMethod_Check is not accepting compiled form, we just go by attributes. |
