diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2011-01-06 18:45:44 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:51:44 -0300 |
commit | ece91be2e6ab129085d372ce3aac08d4073b42ec (patch) | |
tree | 79174267f9a11fce73eeec9f7dd12c7dda155015 /PySide | |
parent | 42e52dec9cd5db837a9fda2663b9c873dac1cd7b (diff) |
Fixes connecting signal to decorated slot.
Decorated methods on classes derived from QObject are not called when
connected to Qt signals because they get a name different from the
decorated method. To solve this decorated methods are registered as
global slots.
An unit test was added.
Reviewed by Hugo Parente <hugo.lima@openbossa.org>
Reviewed by Renato Araújo <renato.filho@openbossa.org>
Diffstat (limited to 'PySide')
-rw-r--r-- | PySide/QtCore/glue/qobject_connect.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/PySide/QtCore/glue/qobject_connect.cpp b/PySide/QtCore/glue/qobject_connect.cpp index 91c830abd..f6b0dce08 100644 --- a/PySide/QtCore/glue/qobject_connect.cpp +++ b/PySide/QtCore/glue/qobject_connect.cpp @@ -1,9 +1,20 @@ +static bool isDecorator(PyObject* method, PyObject* self) +{ + Shiboken::AutoDecRef methodName(PyObject_GetAttrString(method, "__name__")); + if (!PyObject_HasAttr(self, methodName)) + return true; + Shiboken::AutoDecRef otherMethod(PyObject_GetAttr(self, methodName)); + return otherMethod.object() != method; +} + static bool getReceiver(PyObject* callback, QObject** receiver, PyObject** self) { + bool forceGlobalReceiver = false; if (PyMethod_Check(callback)) { *self = PyMethod_GET_SELF(callback); if (Shiboken::Converter<QObject*>::checkType(*self)) *receiver = Shiboken::Converter<QObject*>::toCpp(*self); + forceGlobalReceiver = isDecorator(callback, *self); } else if (PyCFunction_Check(callback)) { *self = PyCFunction_GET_SELF(callback); if (*self && Shiboken::Converter<QObject*>::checkType(*self)) @@ -14,7 +25,7 @@ static bool getReceiver(PyObject* callback, QObject** receiver, PyObject** self) *self = 0; } - bool usingGlobalReceiver = !*receiver; + bool usingGlobalReceiver = !*receiver || forceGlobalReceiver; if (usingGlobalReceiver) { PySide::SignalManager& signalManager = PySide::SignalManager::instance(); *receiver = signalManager.globalReceiver(); |