QSettings array increasing the size?
-
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!
-
-
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.
-
-
@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(); }