[Solved] ini File Location for QSettings



  • Hello All,

    I have a configuration file I want to read that is already made. I would like to just read values from the file. Or better yet, my overall goal is if the file is none existent, create the file with default settings

    Heres what I am trying to do to read the current ini file. I just has some com port settings in it.

    @
    QSettings settings("config/iosettings.ini", QSettings::IniFormat);
    // get settings...
    configstruct.ipaddress = settings.value("settings/ipaddress", "0"); // ip address
    configstruct.portname = settings.value("settings/portname", "0"); // comm port
    configstruct.baudrate = settings.value("settings/baudrate", "0"); // baud
    configstruct.stopbits = settings.value("settings/stopbits", "0"); // stop bits
    configstruct.parity = settings.value("settings/parity", "0"); // parity
    configstruct.flowcontrol = settings.value("settings/flowcontrol", "0"); // flow control
    // end group...
    @

    my question is, where should I put my file? I have it currently in the project directory in a folder called config.

    So the file path is config/iosettings.ini

    This is what my ini file looks like:
    [settings]
    ipaddress=0.0.0.0
    portname=ttyUSB0
    baudrate=9600
    stopbits=1
    parity=no
    flowcontrol=no

    When my code snipet completes, I receive all 0's which is the default. This tells me the file location is not being read correctly.

    Any one give me some insight on where to put the .ini file?

    I read the QSettings documentation, but I have tried multiple things, but have had no success yet.





  • ... which is usually the out-of-source build directory without build version (debug / release) for relative paths. You'll find the working directory in QtCreators Project tab.

    When deploying your application the configuration files should not be stored in the applications directory (as it is usually not writeable). They should go to QDesktopServices::storageLocation(QDesktopServices::DataLocation), usually combined with QCoreApplication::organizationName() and QCoreApplication::applicationName() instead.



  • Thank you guys for the insight! Problem solved. I read the QSettings Basic Usage docs, default format, and what not and got it all working perfectly! Thank you!


Log in to reply
 

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