Results 1 to 6 of 6

Thread: QSettings problem!

  1. #1
    Join Date
    May 2009
    Posts
    21
    Thanks
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QSettings problem!

    Hi,
    saving values with qsettings works out of the box for "normal" variables (not pointers), but with pointer variables it doesn't work.

    WORKING VERSION:

    Qt Code:
    1. QString myString;
    2. int myInt;
    3.  
    4. settings = new QSettings("test", "lol");
    5. settings->beginGroup("lol");
    6. myString = settings->value("myString").toString();
    7. myInt = settings->value("myInt").toInt();
    8. settings->endGroup();
    9.  
    10. std::cout << qPrintable(myString) << std::endl;
    11. std::cout << myInt << std::endl;
    To copy to clipboard, switch view to plain text mode 

    NOT WORKING VERSION
    Qt Code:
    1. QString *myString = new QString;
    2. int *myInt = new int;
    3.  
    4. settings = new QSettings("test", "lol");
    5. settings->beginGroup("lol");
    6. *myString = settings->value("myString").toString();
    7. *myInt = settings->value("myInt").toInt();
    8. settings->endGroup();
    9.  
    10. std::cout << qPrintable(*myString) << std::endl;
    11. std::cout << *myInt << std::endl;
    To copy to clipboard, switch view to plain text mode 

    can anyone explain me why qsettings with pointer variables doesn't work?
    Or where i am wrong?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings problem!

    How does "not working" occur? The values are incorrect, empty or what?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings problem!

    How do you write the settings?
    A camel can go 14 days without drink,
    I can't!!!

  4. #4
    Join Date
    May 2009
    Posts
    21
    Thanks
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSettings problem!

    i didn't rewrite the settings, because i am using the same used for the working version, so the settings are saved correctly previously...

    When i read in this mode the settings, the varaibles are empty! I tried myString.isEmpty() and it gives me 'true'

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings problem!

    Works fine for me...

    Qt Code:
    1. #include <QSettings>
    2. #include <QString>
    3. #include <QtDebug>
    4.  
    5. int main(int argc, char **argv){
    6. QSettings settings("test.ini", QSettings::IniFormat);
    7. QString *str = new QString;
    8. if(argc<2){
    9. *str = "xyz";
    10. settings.setValue("test", *str);
    11. } else {
    12. *str = settings.value("test").toString();
    13. qDebug() << *str;
    14. }
    15. return 0;
    16. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    0xl33t (28th July 2009)

  7. #6
    Join Date
    May 2009
    Posts
    21
    Thanks
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSettings problem!

    I launched make clean and recompiled the code again, now it's working fine! O.o

    The same code! Very strange!


    thanks anyway!!!

Similar Threads

  1. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 13:05
  2. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 15:38
  3. Problem with QSettings
    By arbi in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2008, 09:49
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 13:45
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 22:36

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.