[PyQt] Saving PyObjects QSettings
Paul Giannaros
paul at giannaros.org
Thu Jul 31 15:12:54 BST 2008
On Thu, Jul 31, 2008 at 3:11 PM, Paul Giannaros <paul at giannaros.org> wrote:
> You do not need two config files this way. For example:
>
> o = pickle.dumps(myDevices)
> settings.setValue('test', QVariant(o))
> print pickle.loads(str(settings.value(o).toString()))
>
Sorry, that last line should have been
print pickle.loads(str(settings.value('test').toString()))
> On Thu, Jul 31, 2008 at 2:57 PM, Lukas <LuHe at gmx.at> wrote:
>> 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
>> _______________________________________________
>> PyQt mailing list PyQt at riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
>
More information about the PyQt
mailing list