QSettings is not saving my data



  • Hello there,

    I'm trying to create an ini file which is reading file and everything, but it's not writing to my file, I have this file as a resource and here is my code

    @ QSettings test (":/configs/test.ini",QSettings::IniFormat);
    ui->label->setText(test.value("System.Setting/auto_check_update","Error").toString());
    ui->label_2->setText(test.value("System.Setting/selected_language","Error").toString());
    ui->label_3->setNum(test.value("System.Setting/firstTime",5).toInt());
    if(ui->label_3->text().toInt()==1)
    {
    ui->label_4->setText("This is out first time");
    test.setValue("System.Setting/firstTime",0);
    test.sync();
    }
    else
    {
    ui->label_4->setText("this is not out first time");
    }
    @

    and I tried to make it for desktop and send it to my mobile,

    But every time I only see a message which is This is our first time, and value is always 1, it never writes 0 to it.

    Also I wanted my to list my file in the .pro instead of adding it to a resource file with no success, thank you.

    Ahmed



  • Hi,

    The resources are read-only, so nothing you modify in the QSettings object will be saved.

    bq. Also I wanted my to list my file in the .pro instead of adding it to a resource file with no success

    You could create a new "Mobile Qt Application" project in QtCreator: it adds a deployment.pri to you project to copy files or directories to the target directory (it works for desktop application too).

    Or if you want to keep your existing project, copy the file shared/deployment.pri from QtCreator templates directory QtSDK/QtCreator/share/qtcreator/templates to your project and add the following lines (from mobileapp/app.pro) to your .pro file:
    @# To copy the whole directory
    dirToCopy.source = config
    DEPLOYMENTFOLDERS = dirToCopy

    OR if you only want to copy one file

    fileToCopy.source = config/test.ini

    fileToCopy.target = config # to recreate the directory in the destination

    DEPLOYMENTFOLDERS = fileToCopy

    Please do not modify the following two lines. Required for deployment.

    include(deployment.pri)
    qtcAddDeployment()
    @



  • If you like you can take a look at the following "simple code snippet for QSettings":http://developer.qt.nokia.com/wiki/How_to_Use_QSettings



  • Wow, thanks for that guys, Sorry I've been late but I just had the time to be back, have a great day ;)

    Ahmed


Log in to reply
 

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