[PyQt] setValue of QSettings adds undesired whitespaces in settings file

Luca Fasano lucafasano at interfree.it
Mon Jun 29 09:38:33 BST 2009


Hi all,
As described in mail subject, I noticed that if you use setValue()
method of a Qsettings object, undesired whitespaces are added to
settings file. For example if you have an entry consisting of a comma
separated list, whitespaces are added in it, even if setValue() only
adds a *new* group.
This is not a trivial bug if you want to use the same file for both
QSettings and logging configuration. In fact logging.config.fileConfig()
method does not recognize comma separated lists with whitespaces.

Here is a very simple example:
 - starting .ini file:

[group_base]
key1=value1,value2,value3 #warning! this list has to contain comma
#separated value *without* whitespaces when script starts


 - python script:

import os, sys
from PyQt4 import QtGui, QtCore

class MainWin(QtGui.QMainWindow):
    def __init__(self, *args):
        super(MainWin, self).__init__(*args)
        self.settings = QtCore.QSettings('./settings.ini',
QtCore.QSettings.IniFormat, self)

    def changeSettings(self):
        settings = self.settings
        settings.beginGroup('added_group')
        settings.setValue('added_key', QtCore.QVariant('added_value'))
        settings.endGroup()

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    m = MainWin()
    m.changeSettings()
    m.show()
    os._exit(app.exec_())



 - .ini file after script execution (with .ini file in same folder of
script):

[group_base]
key1=value1, value2, value3 #warning! this list has to contain comma
#separated value *without* whitespaces when script starts

[added_group]
added_key=added_value


Notice whitespaces between value1, value2 and value3!!!!

Thanks







More information about the PyQt mailing list