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

Windows: QSettings problem (cannot read) when input file is a symlink

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.10.1
    • 5.3.2, 5.9.2
    • Core: Other
    • None
    • 22ec92a201beb9ec4bb6a7e21fcfdc8cd9b884f9 (qtbase/5.10, 2.12.2017, 5.10.1)

    Description

      Hi, i'm having problems loading settings with QSettings on a windows machine.
      I have a symlink file in the Project/debug folder that points to another file in another folder (writable and readable) when I try to read some setting from that file it behave like the file doesn't exists, when I try to write some settings on that link it overwrites the entire file deleting all the settings in it.
      The link file is a symlink, not a normal shortcut (that doesn't work either, the same behavior is triggered) is created with the windows tool mklink using the command:

      mklink test.ini "D:\usr\test.ini"

      main.cpp:

       

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include <QSettings>
      #include <Qdir>
      #include <QCoreApplication>
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
          if (engine.rootObjects().isEmpty())
              return -1;
      
          qInfo(QString(QCoreApplication::applicationDirPath()+"/test.ini").toLatin1().data());
          QSettings* _persisted_repository = new QSettings(QCoreApplication::applicationDirPath()+"/test.ini", QSettings::IniFormat);
          _persisted_repository->setValue("aa","false");
          //_persisted_repository->setValue("bb","false");
          _persisted_repository->setValue("cc","false");
      
          qInfo(_persisted_repository->value("bb").toString().toLatin1().data());
      
          _persisted_repository->sync();
      
          return app.exec();
      }
      

       even if the setting "bb=false" is originally in the file it disappear and this line has a null output in the console:

       qInfo(_persisted_repository->value("bb").toString().toLatin1().data());
      

      P.S: this behavior is not triggered with a file that is not a link or a simlink, the same code with "test.ini" as a normal file works fine

      Attachments

        For Gerrit Dashboard: QTBUG-64121
        # Subject Branch Project Status CR V

        Activity

          People

            thiago Thiago Macieira
            damre22 Damiano Rebuzzi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes