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

Data type in QSettings

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.12.2
    • Fix Version/s: 5.12.5, 5.13.1
    • Component/s: PySide
    • Labels:
      None
    • Platform/s:
      All
    • Commits:
      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

          For Gerrit Dashboard: PYSIDE-1010
          # Subject Branch Project Status CR V

            Activity

              People

              Assignee:
              crmaurei Cristian Maureira-Fredes
              Reporter:
              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