Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1010

Data type in QSettings

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.12.5, 5.13.1
    • 5.12.2
    • PySide
    • None
    • All
    • 78dad8180d797a647645b74255bfc29c46d7264a (pyside/pyside-setup/5.12)

    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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              eyllanesc Edwin Christian Yllanes Cucho
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes