Qt QSettings is trying to create an ini file, but no one has created why?

I am trying to create an ini file that will save me configuration data, I have a singleletone class that setting the QSettings object looks like this:

 ... #DEFINE CONFIG_FILE_NAME "myconfig.ini" m_pSettings = new QSettings(QDir::currentPath()+"/"+CONFIG_FILE_NAME,QSettings::IniFormat); 

this accumulates the document, but when I look in my dir application, there is no myconfig.ini file, what am I doing wrong?

+4
source share
2 answers

I believe that in order to make the QSettings file appear, you will need to set at least one value in it and then call the sync () method. See if the example below works:

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

hope this helps, believes

+11
source

I do not think that "/" + CONFIG_FILE_NAME returns the expected result. May be the cause of your problem .. In any case, the + () operator is present in the QString class, so QDir :: currentPath () + "/my_config_file.ini" should work fine.

-1
source

Source: https://habr.com/ru/post/1346432/


All Articles