[PyQt] Unsatisfactory behaviour of QSettings

Baz Walter bazwal at ftml.net
Fri May 30 16:56:14 BST 2014


On 30/05/14 14:41, Phil Thompson wrote:
> I can't reproduce this using any of the Python2/PyQt4, Python3/PyQt4 and
> Python3/PyQt5 combinations.

Sorry: my fault for not specifying the platform.

Just so we're on the same page, here's a test script:

=======>8=======

from PyQt4 import QtCore
# from PyQt5 import QtCore

def set_option(key, value):
     s = QtCore.QSettings('test', 'test')
     s.setValue('section/%s' % key, value)

def get_option(key, default=None, typeinfo=None):
     s = QtCore.QSettings('test', 'test')
     try:
         if typeinfo is None:
             return s.value('section/%s' % key, default)
         return s.value('section/%s' % key, default, typeinfo)
     except TypeError as exception:
         return exception

set_option('key1', [])
print(repr(get_option('key1', [])))
print(repr(get_option('key1', [], 'QStringList')))

set_option('key2', ['a'])
print(repr(get_option('key2', [])))
print(repr(get_option('key2', [], 'QStringList')))

=======>8=======

Output for me on Linux with python2 and pyqt4:

<PyQt4.QtCore.QVariant object at 0x1b39cf8>
TypeError('unable to convert a QVariant of type 0 to a QMetaType of type 
11',)
<PyQt4.QtCore.QVariant object at 0x1b39cf8>
[<PyQt4.QtCore.QStringList object at 0x1b39cf8>]

with python3 and pyqt4/pyqt5:

None
TypeError('unable to convert a QVariant of type 0 to a QMetaType of type 
11',)
['a']
[['a']]

The test.conf file looks like this (all combinations):

[section]
key1=@Invalid()
key2=@Variant(\0\0\0\t\0\0\0\x1\0\0\0\n\0\0\0\x2\0\x61)

On Windows, the corresponding output is:

<PyQt4.QtCore.QVariant object at 0x00B65770>
<PyQt4.QtCore.QStringList object at 0x00B65770>
<PyQt4.QtCore.QVariant object at 0x00B65770>
<PyQt4.QtCore.QStringList object at 0x00B65770>

and:

[]
[]
['a']
['a']

-- 
Regards
Baz Walter


More information about the PyQt mailing list