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

QSettings::value("Theme") returns an empty QByteArray if beginGroup has been called

    XMLWordPrintable

Details

    • e8e818df9 (dev), 450fdee83 (6.7), 9452e8d7d (6.6)

    Description

      Calling allKeys() beforehand makes it work:

      #include <QCoreApplication>
      #include <QSettings>
      #include <QDebug>
      #include <QFile>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          const QString settingsFilePath = QString::fromUtf8(APP_SOURCE_DIR) + "/settings.conf";
          if (!QFile::exists(settingsFilePath)) {
              qWarning() << settingsFilePath << "doesn't exist";
              return 1;
          }
      
          qDebug() << "Found settings file at" << settingsFilePath;
      
          QSettings settings(settingsFilePath, QSettings::IniFormat);
          settings.beginGroup("Material");
          // This makes it work:
          // qDebug() << "allKeys" << settings.allKeys();
      
          const QByteArray themeValue = settings.value("Theme").toByteArray();
          qDebug() << "themeValue" << themeValue;
      
          return 0;
      }
      

      The syntax in the INI file was taken from the comment here. I would think it should be ignored (since it has no values under it), rather than cause faulty behaviour:

      [Controls]
      Style=ResourceStyle
      FallbackStyle=Material
      
      [Material]
      Theme=Dark
      [Material\Font]
      

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            mitch_curtis Mitch Curtis
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes