Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with saving arrays with QSettings, may be a bug
Forum Updated to NodeBB v4.3 + New Features

Problem with saving arrays with QSettings, may be a bug

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dissidia
    wrote on last edited by
    #1

    Hello guys,could you help me finding the problems?really i don't understand where the problem is, the save part is surely correct since the output file is exactly as the documentation states but as soon as i try to load the setting file nothing gets loaded since the size of SettingsObject.beginReadArray("DllPaths") is always 0,got any idea?? thanks in advice..

    @void Options::closeEvent(QCloseEvent *event)
    {
    QString SettingsPath = QApplication::applicationDirPath() + "/Settings/Options";
    if (!QDir(SettingsPath).exists())
    QDir().mkdir(SettingsPath);

    QSettings SettingsObject(SettingsPath + "/OptionSettings.ini",QSettings::IniFormat);

    SettingsObject.beginGroup("MapleStoryPath");
    SettingsObject.setValue("PathMS",ui.lineDir->text());
    SettingsObject.endGroup();

    SettingsObject.beginWriteArray("DllPaths");
    for (int i = 0; i < DllList.size(); i++)
    {
    SettingsObject.setArrayIndex(i);
    SettingsObject.setValue("DllName", DllList.at(i).DllName);
    SettingsObject.setValue("DllPath", DllList.at(i).DllPath);
    }
    SettingsObject.endArray();
    }

    void Options::LoadSettings()
    {
    QList<DllStruct> ListToLoad;
    QString MySettings = QApplication::applicationDirPath() + "/Settings/Options/OptionSettings.ini";
    QSettings SettingsObject(MySettings,QSettings::IniFormat);

    SettingsObject.beginGroup("MapleStoryPath");
    QString MaplePath = SettingsObject.value("PathMS","").toString();
    ui.lineDir->setText(MaplePath);
    SettingsObject.endGroup();

    DllStruct DllEntry;
    for (int i = 0; i < SettingsObject.beginReadArray("DllPaths") ; i++)
    {
    SettingsObject.setArrayIndex(i);
    DllEntry.DllName = SettingsObject.value("DllName").toString();
    DllEntry.DllPath = SettingsObject.value("DllPath").toString();
    ListToLoad.append(DllEntry);
    }

    if (!ListToLoad.isEmpty())
    AddDll(ListToLoad);

    SettingsObject.endArray();
    }

    void Options::AddDll(QList<DllStruct> ListToLoad)
    {
    QTreeWidget* Tree = this->ui.treeWidgetDlls;
    QTreeWidgetItem* TreeItems = new QTreeWidgetItem(Tree);

    for (int i = 0; i < ListToLoad.size(); i++)
    {
    TreeItems->setText(0, ListToLoad.at(i).DllName);
    TreeItems->setText(1, ListToLoad.at(i).DllPath);
    this->ui.treeWidgetDlls->addTopLevelItem(TreeItems);
    }
    }
    @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      I would suggest to move SettingsObject.beginReadArray("DllPaths") out of loop. Something like this:
      @
      int size = SettingsObject.beginReadArray("DllPaths");
      for (int i = 0; i < size; ++i)
      {
      SettingsObject.setArrayIndex(i);
      DllEntry.DllName = SettingsObject.value("DllName").toString();
      DllEntry.DllPath = SettingsObject.value("DllPath").toString();
      ListToLoad.append(DllEntry);
      }
      @

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved