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

Reading of modified settings with QSettings does not work

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: P2: Important P2: Important
    • None
    • 5.4.1
    • Core: I/O
    • None
    • yosemite

      The protocol for the bug would be:

      Build and launch the following (clumsy and stupid) application:

      main.cpp
      #include <QCoreApplication>
      #include <QObject>
      #include <QDebug>
      #include <QSettings>
      #include <QSharedPointer>
      #include <QTimer>
      
      class Logger: public QObject
      {
      public:
        void onAboutToQuit()
        {
          QSettings s;
          qDebug() << "filename" << s.fileName();
          QVariant variant = s.value("mySetting", QVariant(true));
          qDebug() << "valid?" << variant.isValid();
          qDebug() << "variant" << variant;
          bool value = variant.value<bool>();
          qDebug() << "value" << value;
          s.setValue("mySetting", value);
          value = s.value("mySetting").value<bool>();
          s.sync();
          qDebug() << "value" << value;
          qDebug() << "status" << s.status();
        }
      };
      
      int main(int argc, char *argv[])
      {
        QCoreApplication a(argc, argv);
        a.setOrganizationName("QtCompany");
        a.setOrganizationDomain("www.qt-project.org");
        a.setApplicationName("TestSettings");
        a.setApplicationVersion("0.0.1");
        QSharedPointer<Logger> l(new Logger);
        QObject::connect(&a, &QCoreApplication::aboutToQuit,
          l.data(), &Logger::onAboutToQuit);
        QSharedPointer<QTimer> t(new QTimer);
        QObject::connect(t.data(), &QTimer::timeout, &a, &QCoreApplication::quit);
        t->setInterval(0);
        t->start();
        return a.exec();
      }
      

      Edit the plist file given by the application output with the standard plist editor of Mac OS (a component of XCode).
      Set the value of "mySetting" from "YES" to "NO".
      Re-run the application.

      We would expect the output to find the value false for "mySetting", but it is still true.

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

            vestbo Tor Arne Vestbø
            JFremy Julien Fremy
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes