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

半腔热情 提交于 2020-01-02 04:08:16

问题


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 ?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/5529263/qt-qsettings-try-to-create-ini-file-but-none-created-why

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!