Can't get QSettings to write my settings properly
-
Hi,
@radu-m10 said in Can't get QSettings to write my settings properly:
QFont font = setting.value("text.font",QString()).toString();
setting.beginGroup("MainWindow");These two lines are not in the correct order.
Also, your "text.font" content comes from toString so you should use the QFont::fromString method to load these data. -
@SGaist I swapped those lines.
I am sorry I am a complete newbie but I don't really understand the fromString() part. I don't know where and what to replace. Do you mean in the loadSettings function or saveSettings function? I don't know where to call that method. -
Did you read the QFont toString and fromString documentation ?
@SGaist said in Can't get QSettings to write my settings properly:QFont font = setting.value("text.font",QString()).toString();
That's the line I suggest to fix.
-
@SGaist I've read it. I understand what it should do but still I don't exactly know how to implement it. If I just change .toString with .fromString() it doesn't work. Also I don't know where the parameter "&description" should come from. Also, this might fix some things about loading the settings but still, the save function doesn't even change the output of the font size in the config file which is just an integer. It just stays at a default "9".
-
Nowhere was it written that you should change your toString line.
The description is what you stored in the QSettings under "text.font".
-
@SGaist Ok, thanks. I got my head around that. Now I still have the saving issue. Did you spot any mistakes in the save function?
Whenever I hit the save button the settings just revert to default values. Could it be something with "this->font()" ?
If I initialize a font with exact parameters it seems to work. But the save function saves just defaults even if I change the font inside the editor and save afterwards. -
@radu-m10 said in Can't get QSettings to write my settings properly:
QFont font = setting.value("text.font",QString()).toString();
setting.beginGroup("MainWindow");
QString fontFamily = setting.value("text.font.family",QString()).toString();
int fontSize = setting.value("text.font.size",12).toInt();
setting.setValue("text.font.size",fontSize);
//bool fontIsBold = setting.value("text.font.bold",false).toBool();
//bool fontIsItalic = setting.value("text.font.italic",false).toBool();
setFont(font);
font.setPointSize(fontSize);
setting.endGroup();
qDebug() << "Loaded";You should cleanup that function, you call setFont before finishing setting the font's parameters.