Details
Description
The following code stores a list with QSettings:
from PySide2 import QtCore settings = QtCore.QSettings('Foo', 'Bar') if settings.value('ids') is None: item_list = ['a', 'b', 'c'] settings.setValue('ids', item_list) else: r = settings.value('ids') print(r, type(r))
The previous code must be executed twice, in the first execution it saves the list, and in the second execution the list is obtained correctly.
['a', 'b', 'c'] <class 'list'>
But if you pass a list of a single element of type string in the second invocation you get as a string instead of the list:
from PySide2 import QtCore settings = QtCore.QSettings('Foo2', 'Bar2') if settings.value('ids') is None: item_list = ['a'] settings.setValue('ids', item_list) else: r = settings.value('ids') print(r, type(r))
Output:
a <class 'str'>
In PyQt5, the QSettings::value() method has an argument that can be used to indicate the type of data that is expected to avoid this type of problem.
Attachments
Issue Links
- depends on
-
PYSIDE-1017 Support named variables while adding functions in the typesystems
- Closed
- relates to
-
PYSIDE-1624 QSettings.value docs need explanation of when None returned
- Reported
-
PYSIDE-2381 QSettings list of strings does not roundtrip
- Reported
For Gerrit Dashboard: PYSIDE-1010 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
263350,9 | Add optional support for types in QSettings::value | 5.12 | pyside/pyside-setup | Status: MERGED | +2 | 0 |