[PyQt] Saving PyObjects QSettings

Lukas LuHe at gmx.at
Thu Jul 31 14:57:36 BST 2008


Hello,
yes I know, but the disadvantage is that I need two config files, so this is 
just me last resort
Can I convert a list() to/from a QList() and save then this? Are QLists 
available in PyQt?

On Thursday 31 July 2008 15:47:10 Paul Giannaros wrote:
> You could just use the pickle module and save and load from the
> resulting string. I'm not sure if there's a "better" way to do it,
> however.
>
> On Thu, Jul 31, 2008 at 2:38 PM, Lukas <LuHe at gmx.at> wrote:
> > Hello,
> >
> > I wanted to save a PyObject in my QSettings:
> >>>> from PyQt4.QtGui import *
> >>>> app = QApplication([])
> >>>> settings = QSettings()
> >>>>
> >>>> myDevices = list()
> >>>> device = dict()
> >>>> device["name"] = "just some testing"
> >>>> device["addr"] = "00:22:33:5A:52"
> >>>> myDevices.append(device)
> >>>>
> >>>> QVariant(myDevices)
> >
> > <PyQt4.QtCore.QVariant object at 0x7f682c6b7c00>
> >
> >>>> QVariant(myDevices).toPyObject()
> >
> > [{'name': 'just some testing', 'addr': '00:22:33:5A:52'}]
> >
> > But when I try to save this I get the following error:
> >>>> settings.setValue("test", QVariant(myDevices))
> >>>> QVariant::save: unable to save type 446.
> >
> > Is there a way to save python objects?
> >
> > Thanks,
> >
> > Lukas Hetzenecker
> > _______________________________________________
> > PyQt mailing list    PyQt at riverbankcomputing.com
> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt


More information about the PyQt mailing list