On Friday 15 April 2011 14:08:48 anatoly techtonik wrote:
> On Fri, Apr 15, 2011 at 5:10 PM, Hugo Parente Lima
> 
> <[email protected]> wrote:
> >> 2. Clean roundtripping behavior (silently taking False and turning it
> >> into u'false' -- a true value in python! -- is very dangerous).  I'd
> >> rather get a ValueError when trying to set the value than have it get
> >> silently coerced to a string like that.
> > 
> > You need to understand that the problem isn't in PySide itself, the
> > problem is in Qt that stores every type as string in QSettings no matter
> > if it's a bool, a int, etc..
> 
> Is it possible to provide a wrapper on a Py.side that serializes
> values with type information and recommend to use it?
> If it is not possible, it may be possible to require string arguments
> to setValue(). Because u'false' == true is definitely weird and
> reminds me of PHP.

It's possible, the only problem will be that the value stored will not be what 
you see in your problem, e.g.

We could always put a character to specify the type, so if you write:

s = QSettings(...)
s.setValue("key", "2")
# We store the string "s2"
s.setValue("key", 2)
# We store the string "n2"
s.setValue("key", "false")
# We store the string "sfalse"
s.setValue("key", false)
# We store the string "b0"
s.setValue("key", 2.5)
# We store the string "f2.5"

the value() method would read the first character to identify and return the 
correct type.

But IMO this should be implemented as an extension to avoid data corruption on 
already existent application, something enabled with a method like.

QSettings.enableSafeTypes()
or
QSettings.pysideEnableSafeTypes()

to avoid name clash whatever with future Qt methods, but I prefer the name 
without the "pyside" prefix.

> --
> anatoly t.

-- 
Hugo Parente Lima
INdT - Instituto Nokia de Tecnologia

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside

Reply via email to