[PyQt] QSettings with different Python versions

Phil Thompson phil at riverbankcomputing.com
Tue Apr 9 14:45:00 BST 2013

On Fri, 05 Apr 2013 16:20:58 +0200, Tobias Rzepka
<tobias.rzepka at gmail.com>
> Hello Phil,
> I have encountered some odd behavior in the QSettings if I use the same 
> ini with Python 2 and Python 3. I was able to track the problem down to 
> a entry which is a complex list with dictionaries in it (in the example 
> the ViewProfiles entry from Eric5).
> There are two solutions I've found:
> 1. Delete the ViewProfiles entry
> 2. Access the ini without a default parameter of the QSettings.value
> Detlev and I would like to implement the second solution because users 
> who use a old (<=5.3) and new version of Eric5 with different 
> interpreter should see merely no differences in there settings.
> The funny thing is, thats not only the default parameter of the value 
> method but also the surrounding. I've to store the settings in a class 
> (Prefs) and the second parameter has to be from another class, like in 
> the example.
> And if you uncomment the line SingleApplicationMode=false, everything is

> fine again (but also no solution, because the next access is going to
> fail).
> Can you tell, if it's a odd behavior of QSettings or maybe of Python?
> I've attached a ini and a little code snippet from eric5, to demonstrate

> the behavior. The error message is the following:
> Traceback (most recent call last):
>     File "D:\Projekte\Eric5\qsettings\py2_qsettings.py", line 54, in
>     <module>
>       Prefs2.uiDefaults['SingleApplicationMode'])
>     File "C:\Python27\lib\encodings\__init__.py", line 100, in
>     search_function
>       level=0)
>     File "C:\Python27\lib\pickle.py", line 1382, in loads
>       return Unpickler(file).load()
>     File "C:\Python27\lib\pickle.py", line 858, in load
>       dispatch[key](self)
>     File "C:\Python27\lib\pickle.py", line 886, in load_proto
>       raise ValueError, "unsupported pickle protocol: %d" % proto
> ValueError: unsupported pickle protocol: 3
> Thanks. Tobias
> By the way: If I manage to read the ini and save it again, Python 2 
> removes the quotation marks around the ViewProfiles values. Afterwards, 
> the settings file isn't readable in Python 3...

Have you made your example too simple? It works fine for me.


More information about the PyQt mailing list