Qt QSettings try to create ini file but none created why?
Asked Answered
A

2

7

Im trying to create ini file that will hold me the configuration data, I have singletone class that setting the QSettings object like this :

... #DEFINE CONFIG_FILE_NAME "myconfig.ini"

m_pSettings = new QSettings(QDir::currentPath()+"/"+CONFIG_FILE_NAME,QSettings::IniFormat);

this is accourding the document, but when i look in my application dir, there is none myconfig.ini file created, what im doing wrong ?

Apparently answered 3/4, 2011 at 11:18 Comment(4)
are you sure that code is being called? are you certain you are looking in the right directory?Foppery
yeah sure it called , i have break point and log prints that shows that thid code called and the directory is thereApparently
Did you try to set any variable, and then destroy m_pSettings?Mamelon
I ran this code on Qt 4.7.2, same result. The QSettings object is non-null, could call beginWriteArray on it without seg fault.Bess
N
18

I believe in order to force QSettings file to appear you would need to set at least one value in it and then call sync() method. See if an example below would work for you:

QSettings* settings = new QSettings(QDir::currentPath() + "/my_config_file.ini", QSettings::IniFormat);
settings->setValue("test", "value");
settings->sync();

hope this helps, regards

Ninety answered 3/4, 2011 at 13:49 Comment(1)
...or create the QSettings object on stack and let the dtor do the sync.Mightily
C
-1

I dont think that "/"+CONFIG_FILE_NAME return the expected result. May be the cause of your problem.. Anyway operator +() is present in QString class so QDir::currentPath() + "/my_config_file.ini" must work fine.

Conal answered 3/4, 2011 at 17:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.