[PyQt] using pickle to save contents of QSortFilterProxyModel

James Polk jpolk5001 at yahoo.com
Sat Nov 20 01:31:26 GMT 2010

Hi,..I'm trying to save the contents of a QSortFilterProxyModel
(self.proxyModel) as a pickle format file.
The code below appears to work, but unfortunately, there's
nothing in the file....zero size file..

 def saveAsPickle(self):
     fname = "C:/tmp/pick.dat"
     file = open(unicode(fname), "w")
     newModel = self.proxyModel
     pickle.dump(newModel, file)

So, I decided to take step back and save the file as simple text,
and that works fine...so I know the data in self.proxyModel is
good and is there...

After several hours of tinkering and research,...I'm a bit stumped.
I read somewhere...that the statement
    newmodel = self.proxyModel
was necessary,...or advised,..though I'm not totally clear why..

Would it have something to do with the presence of an item in
the database stored as


...which is also printed/saved out as that in the simple text save
function...All other data in the model are simple strings...at least
as of yet,...plan is to add an image/icon in there somewhere..

Although there seem to be a lot of examples out there that 
deal with basic use of pickle,..I haven't found any dealing with
QSortFilterProxyModel....and/or   QTable-, QTree-, QListView...
Is there another preferred way of saving data from these three

This is the class/init part at the top

class Window(QtGui.QWidget):
    def __init__(self):
        super(Window, self).__init__()

        self.proxyModel = QtGui.QSortFilterProxyModel()

Any help or advice would be greatly appreciated,..

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20101119/8f3a1fbb/attachment.html>

More information about the PyQt mailing list