[PyKDE] reference counting and signals&slots

Heinrich Kuettler ql.heiner at web.de
Sun Nov 4 19:07:39 GMT 2001


Hi,

there is a feature in sip I don't understand. I connected a python signal to 
a python slot. And when I emit the signal with an argument (that is, the 
right number of args for this "slot"), the argument's ref-count gets 
increased. This code is meant to illustrate this:

from qt import *

class A( QObject ):
    pass

class B( QObject ):
    def testSlot( self, arg ):
        pass

class Test:

    counter = 0

    def __init__( self ):
        Test.counter += 1

    def __del__( self ):
        Test.counter -= 1

a = A()
b = B()
t = Test()

QObject.connect( a, PYSIGNAL( "testSignal" ), b.testSlot )
a.emit( PYSIGNAL( "testSignal" ), ( t, ) )

del t

# this should be zero
print "Counter:", Test.counter


I think there is an unmatched Py_INCREF in sipEmitToSlot. At least in case 
PyEval_CallObject (qtlib.cpp:300) succeeds the first time it is called. I 
might be wrong, thought.

BTW: I'm using python2.1 and PyQt2.5. However the current (web)cvs version 
doesn't seem to have changed this.

Do you know what is wrong?

Uli

PS: Heinrich doesn't understand this either.




More information about the PyQt mailing list