Update: Extending qt.QApplication & overriding notify appears
to cause a memory leak.

Details: We discovered that the original code sample I posted
also displays a memory leak (with which we have also been struggling).
In the course of investigating that, I've simplified the example
code (minimizing py<->qt interaction) & found that the memory
leak is due to extending qt.QApplication and overriding notify. The 
code below demonstrates this, in addition to the original
complaint of args tending toward QObjects. Memory does not seem to
leak if class App is stubbed-out (i.e., class App(qt.QApplication): pass).
Now to isolate the leak...

Alan Harkreader


##################################################################
import sys
import qt

class App(qt.QApplication):
    def notify(self, receiver, event):
        if event.type() == qt.QEvent.FocusIn:
            print 'focus-in', receiver
        return qt.QApplication.notify(self, receiver, event)

class Toggle:
    wnd = None
    def __call__(self):
        if self.wnd:
            print 'close', self.wnd
            self.wnd.close(1)
            self.wnd = None
        else:
            self.wnd = qt.QMainWindow()
            main = qt.QWidget(self.wnd)
            self.wnd.setCentralWidget(main)
            layout = qt.QVBoxLayout(main)
            layout.addWidget(qt.QLineEdit(main))
            layout.addWidget(qt.QLineEdit(main))
            self.wnd.show()
            print 'open', self.wnd
Toggle = Toggle()

if __name__ == '__main__':
    app = App(sys.argv)
    wnd = qt.QMainWindow()
    btn = qt.QPushButton('Click', wnd)
    btn.resize(btn.sizeHint())
    btn.connect(btn, qt.SIGNAL('clicked()'), Toggle)
    wnd.show()
    app.connect(app, qt.SIGNAL('lastWindowClosed()'), app, qt.SLOT('quit()'))
    app.exec_loop()




_______________________________________________
PyKDE mailing list    [EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde

Reply via email to