Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSettings is not saving my data
Qt 6.11 is out! See what's new in the release blog

QSettings is not saving my data

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 8.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    q8phantom
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexisdm
      wrote on last edited by
      #2

      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()
      @

      1 Reply Last reply
      0
      • L Offline
        L Offline
        leon.anavi
        wrote on last edited by
        #3

        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

        http://anavi.org/

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          q8phantom
          wrote on last edited by
          #4

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

          Ahmed

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved