[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:

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.setValue('added_key', QtCore.QVariant('added_value'))

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    m = MainWin()

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

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


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


More information about the PyQt mailing list