[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Saving PyObjects QSettings
From:       "Paul Giannaros" <paul () giannaros ! org>
Date:       2008-07-31 14:12:54
Message-ID: 3cce4fc80807310712v3da06359ub596a91345997b87 () mail ! gmail ! com
[Download RAW message or body]

On Thu, Jul 31, 2008 at 3:11 PM, Paul Giannaros <paul@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@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@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@riverbankcomputing.com
>>> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>> _______________________________________________
>> PyQt mailing list    PyQt@riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
>
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic