Skip to content

Commit e1f1ed8

Browse files
florianlinkmsmolens
authored andcommitted
fixed a missign QMetaObject::disconnect which leads to connection leaking
added removeSignalHandlers() git-svn-id: http://svn.code.sf.net/p/pythonqt/code/trunk@398 ea8d5007-eb21-0410-b261-ccb3ea6e24a9
1 parent c03cd74 commit e1f1ed8

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/PythonQt.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,18 @@ void PythonQtPrivate::removeSignalEmitter(QObject* obj)
13891389
_signalReceivers.remove(obj);
13901390
}
13911391

1392+
void PythonQt::removeSignalHandlers()
1393+
{
1394+
QList<PythonQtSignalReceiver*> signalReceivers = _p->_signalReceivers.values();
1395+
1396+
// just delete all signal receivers, they will remove themselves via removeSignalEmitter()
1397+
foreach(PythonQtSignalReceiver* receiver, signalReceivers) {
1398+
delete receiver;
1399+
}
1400+
// just to be sure, clear the receiver map as well
1401+
_p->_signalReceivers.clear();
1402+
}
1403+
13921404
namespace
13931405
{
13941406
//! adapted from python source file "pythonrun.c", function "handle_system_exit"

src/PythonQt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ class PYTHONQT_EXPORT PythonQt : public QObject {
365365
//! remove a signal handler from the given \c signal of \c obj
366366
bool removeSignalHandler(QObject* obj, const char* signal, PyObject* receiver);
367367

368+
//! globally removes all signal handlers (connections between QObjects and Python).
369+
void removeSignalHandlers();
370+
368371
//@}
369372

370373
//---------------------------------------------------------------------------

src/PythonQtSignalReceiver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ bool PythonQtSignalReceiver::removeSignalHandler(const char* signal, PyObject* c
213213
if (callable) {
214214
while (i.hasNext()) {
215215
if (i.next().isSame(sigId, callable)) {
216+
QMetaObject::disconnect(_obj, sigId, this, i.value().slotId());
216217
i.remove();
217218
foundCount++;
218219
break;
@@ -221,6 +222,7 @@ bool PythonQtSignalReceiver::removeSignalHandler(const char* signal, PyObject* c
221222
} else {
222223
while (i.hasNext()) {
223224
if (i.next().signalId() == sigId) {
225+
QMetaObject::disconnect(_obj, sigId, this, i.value().slotId());
224226
i.remove();
225227
foundCount++;
226228
}

0 commit comments

Comments
 (0)