开发者

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

开发者 https://www.devze.com 2023-02-21 22:27 出处:网络
Im trying to cr开发者_如何学Pythoneate ini file that will hold me the configuration data, I have singletone class

Im trying to cr开发者_如何学Pythoneate 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 ?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号