How to save and read from .ini file using QSetting from the custom path



  • In Qt I am using QSettings class for savine and retrieving the application details. I saved the file as .ini format using QSettings. Also I saved the file in C://Program Files. But the file is created in the AppData/VirtualStore path. Is this is the expected behaviour.

    I want to save and retrieve the file from the custom path like C://Program Files/example/data. But I am not able to read the values from the path. Its always read from the /AppData/VirtualStore/ path.

    I am using windows 8 64 bit and Qt version 5.2.1.

    How I can save and read the .ini file in the custom path what I mentioned.

    Its very helpful any one of you give the solution for this problem.

    Thanks In Advance



  • QSettings provides a constructor that takes a file name. Is that what you are using?

    Anyway, are you sure you want to save to C:\Program Files? Your application can only do this if it runs with elevated rights (as in "Run as Administrator")



  • I copied the ini file into C://Program File/app/test path.

    Now I am reading the ini file using the above path. When i run the application the ini file is copied to AppData/Local/Virtual Store/.

    After that my application using the above path for reading the ini file.
    Now I changed the value in the ini file of my actual path C://Program File/app/test path.

    But the application still took the value from AppData/Local/Virtual Store/ path only.

    Is there any solution for solving the problem.


  • Lifetime Qt Champion

    Hi,

    Even with elevated rights you can't do everything. Ini files don't belong to the same folder as your application especially since you will be writing to it. You have a set of paths you can use (and that are recommended) You can retrieve them use QStandardPaths

    Hope it helps


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.