[PyQt] QPyNullVariant

Wilbert Berendsen wbsoft at xs4all.nl
Thu Jul 26 13:21:57 BST 2012


Op Mon, 16 Jul 2012 12:11:11 +0100
Phil Thompson <phil at riverbankcomputing.com> schreef:

> On Fri, 13 Jul 2012 15:49:48 +0200, Rodolfo Zitellini
> <xhero.gm at gmail.com> wrote:
> > The offending code is in setup.py, when it reads the language:
> >     language = QSettings().value("language", "")
> >     print language
> >     if not language:
> >         try:
> >             language = locale.getdefaultlocale()[0]
> >         except ValueError:
> >             pass
> >     if not language:
> >         language = "C"
> >     return language
> > 
> > in linux, language prints None, on osx it prints QPyNullVariant. it
> > will then evaluate False in "if not language" and then crash when it
> > arrives in __init__.py.
> > 
> > This used to work with qt 4.7 on osx. Just upgrading to 4.8 breaks
> > everything.
> > Any ideas?
> 
> It would suggest that there is a null QVariant stored in the settings
> for "language". If there was no value stored then "" would be
> returned. A workaround would therefore be to update or delete the
> settings data either manually or with a little script.
> 
> Phil

I'm the author of Frescobaldi.

I was not expecting QPyNullVariant() to be returned when I specify a
default value. Why is it that bool(the returned QPyNullVariant)
defaults to True?

What is the best way to check for a possible QPyNullVariant to be
returned from the QSettings().value() method? (I.e. it should also work
on PyQt-4.7 systems).

My code uses QSettings().value almost everywhere. I was happy with the
simple interface, although it would be nice if the returned value would
be forced in the type of the default value if specified.

When I must check for more possible types to be returned, I must create
a wrapper function for it, I guess....


Wilbert




-- 
Wilbert Berendsen
(http://www.wilbertberendsen.nl)



More information about the PyQt mailing list