[PyKDE] SIGNAL-to-SIGNAL connection seems broken

Giovanni Bajo rasky at develer.com
Mon Feb 19 13:13:13 GMT 2007


On 2/18/2007 6:13 PM, Phil Thompson wrote:

>> ==============================================
>> #!/usr/bin/env python
>> from PyQt4.Qt import *
>>
>> a = QObject(None)
>>
>> called = []
>> def myslot():
>>      called.append(True)
>>
>> QObject.connect(a, SIGNAL("destroyed()"), a, SIGNAL("QUIT"))
>> QObject.connect(a, SIGNAL("destroyed()"), myslot)
>> QObject.connect(a, SIGNAL("QUIT"), myslot)
>>
>> del a
>> assert len(called) == 2, len(called)
>> ==============================================
>>
>> This fails for me with PyQt 4.1.1 and SIP-snapshot-20061220 (the slot is
>> invoked only once). I didn't test with newer SIP snapshots though.
> 
> You need to add parenthesis to QUIT as you cannot connect Qt signals to 
> short-circuit signals - connect() returns False.

Given that this feature is specific of SIP/PyQt, wouldn't it better to 
notify the mistake with an exception, rather than returning false? I 
don't think anybody ever checks the return value of connect (examples, 
tutorials, ecc.), so it's not a "common" practice (I wasn't even aware 
connect() *had* a return value...). The C++ version of connect() prints 
some spew on stderr when it fails: adding something like this would be 
also a good solution.

> However there is a bug/feature that is fixed in tonight's PyQt snapshot.

Thanks!
-- 
Giovanni Bajo




More information about the PyQt mailing list