when connecting a Python method to the
QObject.destroyed signal, it seems as
if the connected slot is only called with
one argument instead of two, this results
in :
TypeError: destroyed_slot() takes exactly 2 arguments (1 given)
Error calling slot "destroyed_slot"
while I would expect 2 arguments (self and
the object being destroyed).
am I missing something or is this possibly
a bug ?
Thanks,
Erik
_______________________________________________
PySide mailing list
PyS...@lists.pyside.org
http://lists.pyside.org/listinfo/pyside
The "destroyed()" signal is overloaded, so there are actually two
signals "destroyed()" and "destroyed(QObject)". You apparently
connected to the former. In order to connect to the latter, you need
to explicitly choose the right signature:
"obj.destroyed[QObject].connect(self.destroyed_slot)"
You are right, choosing the right signature works. But how do
you know this signal is overloaded, I cannot see this mentioned
in the docs ?
I don't know about the PySide documentation, but you can easily see
that in the Qt documentation [1]. The signature of "destroyed" is
"QObject::destroyed(QObject *obj=0)". The argument "obj" has a
default value, and C++ implements default values for arguments by
generating overloaded functions.
[1] http://doc.qt.nokia.com/latest/qobject.html#destroyed
Thank you for pointing this out, I was unaware of this
'implementation detail', it seems PyQt handles this case
different.
Really? PyQt should actually handle this case in exactly the same way.
this code always worked perfectly with PyQt. I had the assumption that
a default argument in a signal would be treated the same way as in
Python, this assumption always seemed valid using PyQt
I guess, PyQt just chooses the other overload as default if no
overload was explicity selected. Since you can always use slots with
less arguments than the signal (in which case superfluous arguments
are simply thrown away during invocation of the slot) it makes no
difference in this case.
it raises an exception at connection time when this match fails.
so this seems to be a very different behavior in PySide where the
connect succeeds but the failure is later on when the signal is
emitted ?