Details
-
Bug
-
Resolution: Done
-
Not Evaluated
-
None
-
1.2.x
-
None
Description
From the PyQt docs regarding Python 3 / API 2:
"The QSettings.value() method takes an optional type keyword argument that specifies the type of the value to return. It can either be a Python type object or a string specifying the name of a C++ type.
"Using this argument avoids potential portability problems where the type of a value may not be as expected because the platform specific backend to QSettings may not store the necessary type information."
This does not seem to work on PySide. For bug 981 (http://srinikom.github.io/pyside-bz-archive/981.html) this warning was added to the docs:
"QSettings.value can return different types (QVariant types) depending on the platform it's running on, so the safest way to use it is always casting the result to the desired type, e.g.: int(settings.value("myKey"))".
This is not a correct solution in general. For example, on Linux, bool is written to the settings file as "true" or "false" without type information, and bool("false") == True. Qt does the conversion to string when writing the settings file, so Qt needs to handle the conversion back. Which it does, via QVariant functions like toBool(), but those aren't available in API 2 / PySide.