Important: Please read the Qt Code of Conduct -

What may be the error in following syntax?

  • @QSettings* s = new QSettings(QDir::currentPath() + "/my_file.ini" , QSettings::IniFormat);@

    Here if .ini file does not exist it should create new file but it is not creating.

  • Check the path you're trying to create the file on.

  • i have checked the path is correct

  • Uhm..could it be a problem with the path separator? Have you tried to debug/print the real file name that is created?
    If that is correct, I will try to create an empty file in such directory to see if there is also a permission problem.

  • one thing i notice that if we will setvalue for the first time then only file will be created if it doesn't exist.

  • In the documentation you find:
    @Constructs a QSettings object for accessing the settings stored in the file called fileName, with parent parent. If the file doesn't already exist, it is created.
    However, that is apparently not completely correct. I have just created an object with a fixed path and iniformat. I have not done anythingelse with that object. It was not created.
    When I set a value as you have as you have indicated, the ini-file will be created.

    So QSettings will only create a file, when information is available to be stored.

  • Do you have write access to the QDir::currentPath() directory ?

  • Code is ok. As koahnig told, it will create the ini file, only when you set a value.
    If no values are there, you wouldn't need an empty file right ?

Log in to reply