[PyQt] empty container in QSettings: TypeError

Wilbert Berendsen wbsoft at xs4all.nl
Sun Mar 17 11:39:32 GMT 2013

Hi all,

When I store a list of strings (but happening to be empty) in
QSettings (using QString and QVariant api 2):


>>> paths = []
>>> QSettings().setValue('paths', paths)

Retrieving it yields a TypeError, instead of an empty list:

>>> QSettings().value('paths', [], 'QString')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unable to convert a QVariant of type 0 to a QMetaType of
type 10

What is the most elegant way to circumvent this? cathing the TypeError
and returning the empty list?

Best regards,

Wilbert Berendsen

More information about the PyQt mailing list