Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-3566

Defining custom serialization routines for QSettings

    XMLWordPrintable

Details

    Description

      It would be nice to define custom serialization routines for QSettings. These routines would convert between QVariant and QString. They would be used by QSettingsPrivate::variantToString and QSettingsPrivate::stringToVariant to read and write a wider variety of QVariant types.

      Possibly adding a registration function to QSettings that takes a pointer to an instance of a class with public functions variantToString(QVariant), stringToVariant(QString), tag(), and type(). This class would be derived by the programmer from some abstract base type.

      When QSettings reads "@Tag(text)", where Tag matches the QString returned by the tag() function of one of the registered converters, it invokes stringToVariant(text) on that converter, which parses text and returns a QVariant constructed from it. It returns an invalid QVariant if text is malformed.

      When QSettings tries to write a QVariant value whose type matches the QVariant::Type returned by the type() function of one of the registered converters, it invokes variantToString(value) on that converter, which returns a QString constructed from value. QSettings prepends "@Tag(" and appends ")" to the returned value before actually writing it out.

      One may prefer not to tie this functionality to QSettings but to bundle it with QVariant or QMetaType. This would enable these conversions to be performed for purposes other than configuration, such as printing debug messages.

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            admin Administrator
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes