[PyQt] Dumb question about QDirModel / setModel

David Boddie david at boddie.org.uk
Mon Sep 17 16:56:39 BST 2007


On Mon Sep 17 16:28:34 BST 2007, Nicolas Girard wrote:

> class Window(QtGui.QMainWindow):
>     def __init__(self, parent=None):
>         QtGui.QWidget.__init__(self, parent)
>         self.tree = QtGui.QTreeView(self)
>         model = QtGui.QDirModel()
>         self.setModel(model)
>     def setModel(self,model):
>         tree=self.tree
>         tree.setModel(model)
>         tree.resize(640, 480)

The model is created in a local Python scope without a QObject-derived
parent, so it is destroyed when execution leaves __init__(). The view
does not take ownership of the model because many views could be sharing
the same model.

Your other example kept the model in global scope, so it was only
destroyed when the program exited.

David


More information about the PyQt mailing list