diff options
author | renatofilho <renato.filho@openbossa.org> | 2010-09-16 14:14:45 -0300 |
---|---|---|
committer | renatofilho <renato.filho@openbossa.org> | 2010-09-16 17:12:34 -0300 |
commit | 551f6b9c7240d1f68e50edcec0fc41969beaef1d (patch) | |
tree | 3e6c2878b7b59f3aeb129a5581529ddf4627e760 /libpyside/globalreceiver.cpp | |
parent | c06110168c39e5c44b9b11ff13fd6f9795199df3 (diff) |
Fixed connection cleanup function.
Reviewer: Hugo Parente Lima <hugo.pl@gmail.com>
Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'libpyside/globalreceiver.cpp')
-rw-r--r-- | libpyside/globalreceiver.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/libpyside/globalreceiver.cpp b/libpyside/globalreceiver.cpp index 2dd82aab4..2c126044e 100644 --- a/libpyside/globalreceiver.cpp +++ b/libpyside/globalreceiver.cpp @@ -107,7 +107,6 @@ DynamicSlotData::~DynamicSlotData() Py_DECREF(m_callback); } - GlobalReceiver::GlobalReceiver() : m_metaObject(GLOBAL_RECEIVER_CLASS_NAME, &QObject::staticMetaObject) { @@ -126,20 +125,23 @@ GlobalReceiver::~GlobalReceiver() void GlobalReceiver::connectNotify(QObject* source, int slotId) { if (m_slotReceivers.contains(slotId)) { - m_slotReceivers[slotId]->addRef(source); + DynamicSlotData* data = m_slotReceivers[slotId]; + if (!data->hasRefTo(source)) + QObject::connect(source, SIGNAL(destroyed(QObject*)), this, "1"RECEIVER_DESTROYED_SLOT_NAME); + data->addRef(source); } } void GlobalReceiver::disconnectNotify(QObject* source, int slotId) { - if (m_slotReceivers.contains(slotId)) { - QObject::disconnect(source, SIGNAL(destroyed(QObject*)), this, "1"RECEIVER_DESTROYED_SLOT_NAME); - + if (m_slotReceivers.contains(slotId)) { DynamicSlotData *data = m_slotReceivers[slotId]; data->decRef(source); - if (data->refCount() == 0) { + if (data->refCount() == 0) removeSlot(slotId); - } + + if (!hasConnectionWith(source)) + QObject::disconnect(source, SIGNAL(destroyed(QObject*)), this, "1"RECEIVER_DESTROYED_SLOT_NAME); } } @@ -152,9 +154,8 @@ void GlobalReceiver::addSlot(const char* slot, PyObject* callback) { m_metaObject.addSlot(slot); int slotId = m_metaObject.indexOfSlot(slot); - if (!m_slotReceivers.contains(slotId)) { + if (!m_slotReceivers.contains(slotId)) m_slotReceivers[slotId] = new DynamicSlotData(slotId, callback); - } bool isShortCircuit = true; for (int i = 0; slot[i]; ++i) { @@ -167,6 +168,7 @@ void GlobalReceiver::addSlot(const char* slot, PyObject* callback) if (isShortCircuit) m_shortCircuitSlots << slotId; + Q_ASSERT(slotId >= QObject::staticMetaObject.methodCount()); } @@ -236,12 +238,10 @@ int GlobalReceiver::qt_metacall(QMetaObject::Call call, int id, void** args) retval = PyObject_CallObject(callback, preparedArgs); } - if (!retval) { - qDebug() << "Error calling slot" << m_metaObject.method(id).signature(); + if (!retval) PyErr_Print(); - } else { + else Py_DECREF(retval); - } return -1; } |