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. QSettings array increasing the size?
Forum Update on Monday, May 27th 2025

QSettings array increasing the size?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qsettings
4 Posts 2 Posters 289 Views
  • 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.
  • artwawA Offline
    artwawA Offline
    artwaw
    wrote on last edited by
    #1

    Hello, long time no see.

    I run into some issue with QSettings that I find hard to understand.
    I have an array of visual settings for various components. I update the particular entries based on the user input, nothing special, unusual or complex - or that's what I thought anyway.

    I started to get weird settings misalignment, sections were moving about in the array which I find weird. Perhaps I don't understand how those arrays are supposed to work? Here is the functional bit:

    void PrefsDialog::defaults(const int type, const int section) {
        qDebug() << "section" << section;
        QSettings settings;
        if (type==PrefsDialog::general||type==PrefsDialog::all) {
            settings.beginGroup("general");
    #setValue() calls here
            settings.endGroup();
        }
        if (type==PrefsDialog::visual||type==PrefsDialog::all) {
            if (section==-1) {
                for (auto x=0;x<8;++x) {
                    defaultSection(x);
                }
            } else {
                defaultSection(section);
            }
        }
        if (type==PrefsDialog::tls||type==PrefsDialog::all) {
            settings.beginGroup("tls");
    #setValue() calls here
            settings.endGroup();
        }
        settings.sync();
    }
    

    and a method that is supposed to default each section:

    void PrefsDialog::defaultSection(const int idx) {
        QSettings settings;
        settings.beginWriteArray("visual");
        settings.setArrayIndex(idx);
    #setValue() calls here
        settings.endArray();
    }
    

    The issue: each call to defaultSection() adds entry. So from initial 8, after triggering complete reset, I get 16.
    Why, oh why?

    (Qt 6.7.2, macOS Sonoma 14.5 but also Windows 11, CMake 3.27.7)

    As usual, many thanks in advance!

    For more information please re-read.

    Kind Regards,
    Artur

    1 Reply Last reply
    0
    • artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by
      #2

      I am closing this topic - since no suggestion was given and I can't figure it out, I need to move on and implement something else that actually works.

      For more information please re-read.

      Kind Regards,
      Artur

      1 Reply Last reply
      0
      • artwawA artwaw has marked this topic as solved on
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Can you provide a minimal compilable example with some setValue calls ?
        That would allow us to reproduce your issue in similar fashion as you.

        On a side note, please don't mark threads as solved when they aren't it's misleading for people experiencing the same as you and hoping to find a solution.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        artwawA 1 Reply Last reply
        1
        • artwawA artwaw has marked this topic as unsolved on
        • SGaistS SGaist

          Hi,

          Can you provide a minimal compilable example with some setValue calls ?
          That would allow us to reproduce your issue in similar fashion as you.

          On a side note, please don't mark threads as solved when they aren't it's misleading for people experiencing the same as you and hoping to find a solution.

          artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by artwaw
          #4

          @SGaist Hi, apologies - didn't want to delete and there was no other option...

          EDIT: initial response snippet was unclear! adding more code.

          A small example of values I wanted to put in that loop:

          void PrefsDialog::defaultSection(const int idx) {
              QSettings settings;
              settings.beginWriteArray("visual");
              settings.setArrayIndex(idx);
              settings.setValue("override",false);
              settings.setValue("txtClr",idx==1?"#00F":"#000");
              settings.setValue("u",idx==1?true:false);
              settings.setValue("i",idx==2?true:false);
              settings.setValue("b",(idx>2&&idx<6)?true:false);
              settings.setValue("txtBg","#fff");
              settings.setValue("ident",idx==2?15:0);
              settings.endArray();
          }
          

          For more information please re-read.

          Kind Regards,
          Artur

          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