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

QSettings: preceding slash in key doesn't work.

    XMLWordPrintable

Details

    Description

      See this piece of code for reproducing:

      #include <QSettings>
      #include <QDebug>
      #include <QStringList>
      
      bool readTest(QIODevice&, QSettings::SettingsMap &map)
      {
          map.insert("Test/Test1", "test1");
          map.insert("/Test/Test2", "test2"); // <- this makes trouble...
          return true;
      }
      
      bool writeTest(QIODevice&, const QSettings::SettingsMap&)
      {
          return true;
      }
      
      int main()
      {
          /* Note, the file ~/.config/test/test.settings must exist. */
      
          QSettings::Format testFormat = QSettings::registerFormat( "settings", readTest, writeTest );
          QSettings settings(testFormat, QSettings::UserScope, "test", "test");
      
          qDebug() << settings.allKeys().size();
      
          foreach(QString key, settings.allKeys())
              qDebug() << key << settings.value(key);
      
          /* Note, this works even though we haven't inserted a setting with this
           * name. We have inserted "Test/Test1"(no preceding slash). */
          qDebug() << "value() with leading /" << settings.value("/Test/Test1");
      
          /* This doesn't work.
           */
          qDebug() << "value() with leading /" << settings.value("/Test/Test2");
      
          // Conclusion: somewhere slashes are being stripped. */
          //
          return 0;
      }

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            fenglich Frans Englich (closed Nokia identity)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes