Results 1 to 3 of 3

Thread: QSettings load and write problem in files

  1. #1
    Join Date
    Mar 2011
    Qt products
    Qt4 Qt/Embedded
    Unix/X11 Windows

    Default QSettings load and write problem in files

    i have a little problem with my program.
    I use Qsetting to load and write programsettings in a ini file.
    I write a method to check settings in my file equal the current programsettings and if they are not equal to write the new settings in that file.

    My problem when the Qsetting object can't write the settings in my file (settings in file and programsettings are different and file for test readonly) then say my method by second start that my filesettings and programsettings are equal. What is incorrect.

    my method:

    Qt Code:
    1. void Main::testsetting()
    2. {
    3. mysetting=new QSettings("test.ini",QSettings::IniFormat);
    4. if(mysetting->value("testvalue").toString()==testvalue)
    5. { //second run
    6. QMessageBox::information(this,"Check","Testvalue="+testvalue+ " is equal="+mysetting->value("testvalue").toString(),QMessageBox::Ok);
    7. }
    8. else
    9. { //first run
    10. QMessageBox::information(this,"Check","Testvalue="+testvalue+ " isn't equal="+mysetting->value("testvalue").toString(),QMessageBox::Ok);
    11. }
    12. mysetting->setValue("testvalue",testvalue);
    13. mysetting->sync();
    14. if(mysetting->status() ==QSettings::NoError) QMessageBox::information(this,"Save","Save successful",QMessageBox::Ok);
    15. else QMessageBox::information(this,"Save","Save error",QMessageBox::Ok);
    16. delete mysetting;
    19. }
    To copy to clipboard, switch view to plain text mode 

    The Qsetting class only use local in this method in my program.
    I use Qt 4.7 under Linux and windows the same result.
    Complete example in

  2. #2
    Join Date
    Jan 2009
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    MacOS X Unix/X11 Windows

    Default Re: QSettings load and write problem in files

    I assume, that QSettings uses some kind of caching in order to be able to work normal if the settings file is readonly, since QSettings::sync is called automatically by Qt.

  3. #3
    Join Date
    Mar 2011
    Qt products
    Qt4 Qt/Embedded
    Unix/X11 Windows

    Default Re: QSettings load and write problem in files

    that QtSetting cached the file is ok. But my problem is that all instance of Qsetting objects use this file are destroyed. And I create a new Qsetting Object with this file than use Qsetting a cached version of my config file that is not equal with the orginal file on disk. And this is not really good.

    P.S. sorry for late answer

Similar Threads

  1. QSettings write and read function
    By ivareske in forum Qt Programming
    Replies: 3
    Last Post: 24th February 2011, 15:14
  2. Replies: 1
    Last Post: 14th January 2011, 11:57
  3. Replies: 6
    Last Post: 7th December 2010, 12:32
  4. Replies: 1
    Last Post: 7th March 2010, 16:40
  5. Replies: 4
    Last Post: 1st February 2006, 17:17


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.