Results 1 to 3 of 3

Thread: QSettings does not save...

  1. #1
    Join Date
    May 2007
    Location
    Warsaw, Poland
    Posts
    52
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSettings does not save...

    I have encountered an obstacle. I use QSettings to store an URL address (as QString) and a QStringList which is then used in creating a List of my MTR::Record objects.

    I save my settings in a destructor of my main QWidget subclass.
    Qt Code:
    1. MyWidget::~MyWidget() {
    2. QVariant var(packRecords(rekordyLokalne));
    3. settings->setValue("rekordyLokalne",var);
    4. //foreach(QString str, var.toStringList()) qDebug() << str;
    5. //foreach(QString str, settings->value("rekordyLokalne").toStringList()) qDebug() << str;
    6. //qDebug() << settings->value("rekordyLokalne").toStringList().count();
    7. }
    To copy to clipboard, switch view to plain text mode 

    where
    Qt Code:
    1. QStringList packRecords(QList<MTR::Records> &);
    To copy to clipboard, switch view to plain text mode 
    is used to serialize a list of my objects to a list of strings.

    Inside a program I manually make a few entries to the rekordyLokalne.

    I expect the code in destructor to save all the data needed but only data attached to "conciseDataURL" is saved. I know it as I check in a destructor (after writing data) and code below (that is used in constructor to read data) the number of items stored in QStringList attached to "rekordyLokalne" key.
    Debug code in destructor says for example 6 entries, while the code from constructor (afer reopening the program) says that there are 0 entries.
    It puzzles me why there are problems with QStringList and everything is okay with QString.

    Heres a method used once in the constructor:
    Qt Code:
    1. void MyWidget::DownloadData() {
    2. settings = new QSettings("MTR","MTR::Mastermind 1.0 PL");
    3. if(settings->value("conciseDataURL") == QVariant())
    4. settings->setValue("conciseDataURL", QVariant("ftp://ftp.mjakobczyk.pl/mastermind.konfig"));
    5. else
    6. settings->setValue("conciseDataURL", settings->value("conciseDataURL"));
    7.  
    8. QString urlek = settings->value("conciseDataURL").toString();
    9. QStringList sl = settings->value("rekordyLokalne").toStringList();
    10. //qDebug() << settings->value("rekordyLokalne").toStringList().count();
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings does not save...

    Do you destroy settings object or call QSettings::sync() anywhere in your code?

  3. #3
    Join Date
    May 2007
    Location
    Warsaw, Poland
    Posts
    52
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings does not save...

    nope, I do not
    Thanks for the hint.
    Last edited by mtrpoland; 28th August 2007 at 13:25.

Similar Threads

  1. Using QSettings to populate a QComboBox
    By nbkhwjm in forum Newbie
    Replies: 16
    Last Post: 4th September 2007, 23:34
  2. Save images to database
    By jnk5y in forum Qt Programming
    Replies: 4
    Last Post: 8th May 2006, 20:56
  3. save animate to gif
    By Dmitry in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2006, 17:35
  4. What does "Save All" actually save?
    By Mariane in forum Newbie
    Replies: 7
    Last Post: 31st January 2006, 14:23
  5. QSettings - beginReadArray not working
    By Mike in forum Qt Programming
    Replies: 7
    Last Post: 9th January 2006, 22:24

Bookmarks

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.