[PyKDE] ref leak in QScrollview

Brent Burley Brent.Burley at disney.com
Fri Nov 16 22:59:11 GMT 2001

It seems that QScrollview leaks references to its children.  Here's an

from qt import *

class MyVBox(QVBox):
    def __del__(self):
	print 'del MyVBox'
    def __init__(self, parent=None):
	QVBox.__init__(self, parent)

class MyScrollView(QScrollView):
    def __del__(self):
	print 'del MyScrollView'
    def __init__(self):
	vbox = MyVBox(self.viewport())
	for i in range(1,21): QLabel('Label %d' % i, vbox)

import sys
app = QApplication(sys.argv)
app.connect(app, SIGNAL("lastWindowClosed()"), app.quit)
ui = MyScrollView()

When you quit the app, MyScrollView gets destroyed, but MyLabel does
not.  Strangely, if you omit the parent when constructing the vbox, the
leak goes away.  This may be an OK workaround, but it is nonstandard Qt
practice and it also means that you cannot place widgets that require a
parent (such as a label) in a scrollview.

	Brent Burley

More information about the PyQt mailing list