qt-interest@trolltech.com
[Top] [All Lists]

AW: AW: AW: QSettings

Subject: AW: AW: AW: QSettings
From: <>
Date: Wed, 16 Nov 2005 10:39:25 +0100
Well, it took me 1.2 minutes to find
http://lists.trolltech.com/qt-interest/2004-02/thread01046-0.html
looking for "save settings" in the mailing list archive.
So much for that.

-----Ursprüngliche Nachricht-----
Von: Dorin Ciobanu [mailto:cdv@xxxxxxxxxxxxx] 
Gesendet: Mittwoch, 16. November 2005 09:10
An: Soukup Michael vatron
Cc: qt-interest@xxxxxxxxxxxxx
Betreff: Re: AW: AW: QSettings

Hi!

Sorry for taking your time. I really tryed to find an answer to my 
original question and did not find it in your reply neither in the 
archives/google/doc.
I just can not make QSettings in QT3.3 (Linux SuSE 9.3) to save data to 
a given file (or at least folder).
For example I need to store data to /etc/myfile.conf, and not to ~/.qt/ 
or /etc/X11/ (witch is default for root user).
In know QT4 there is a constructor for indicating the file.

I hoped to get an answer like: "you need to do this ..." or "it is not 
possible with QT3"

P.S.
If I didn't get it again ... sorry, english is far from being my native :)
If so, please just ignore this message!

Michael.Soukup wrote:

>Well, as far as I found out (by searching the archive *hint*, by which you 
>would do us a favor) QSettings take the first entry before the key name (here 
>"key") with a "rc." added as the file name. 
>
>You can find that in the docs 
>(http://doc.trolltech.com/3.3/qsettings.html#details)
>...
>For example the following code:
>    settings.writeEntry( "/MyApplication/geometry/width", width );
>will end up writing the "geometry/width" setting to the file 
>$HOME/.qt/myapplicationrc (assuming that the application is being run by an 
>ordinary user, i.e. not by root).
>...
>
> 
>regards,
>Michael Soukup
>
>
>-----Ursprüngliche Nachricht-----
>Von: Dorin Ciobanu [mailto:cdv@xxxxxxxxxxxxx] 
>Gesendet: Dienstag, 15. November 2005 10:23
>An: Soukup Michael vatron
>Cc: qt-interest@xxxxxxxxxxxxx
>Betreff: Re: AW: QSettings
>
>In QT3.3 (SuSE 9.3), program bellow creates a file /etc/X11/keyrc
>
>-----
>#include <qsettings.h>
>
>int main(int argc, char *argv[]) {
>   QSettings *settings = new QSettings(QSettings::Ini);
>   settings->setPath("MyCompany.Com", "MyApplication");
>   settings->writeEntry("/Key/MIIMII", "qwerty123");
>   delete settings;
>   return 0;
>}
>
>
>Michael.Soukup wrote:
>
>  
>
>>That is if you are using Qt4
>>With Qt3 I think it is 
>>settings.setPath( "MyCompany.com", "MyApplication" );
>>
>>regards,
>>Michael Soukup
>>
>>
>>-----Ursprüngliche Nachricht-----
>>Von: Dorin [mailto:cdv@xxxxxxxxxxxxx] 
>>Gesendet: Montag, 14. November 2005 20:33
>>An: qt-interest@xxxxxxxxxxxxx
>>Betreff: Re: QSettings
>>
>>I feel ashamed :)
>>I did change free to delete now. And it saves ... but it does that in 
>>/etc/X11/testrc
>>
>>------------ modified code -------------
>>#include <qsettings.h>
>>
>>int main(int argc, char *argv[]) {
>>       QSettings *settings = new QSettings(QSettings::Ini);
>>       settings->insertSearchPath(QSettings::Unix, "/etc/MyFolder/moomoo");
>>       settings->writeEntry("/test1/test2", "tea123");
>>       delete settings;
>>       return 0;
>>}
>>---------------------------------------------
>>
>>I also tried:
>>settings->insertSearchPath(QSettings::Unix, "/etc/MyFolder");
>>Same result :(
>>
>>How can I force config to be stored in some place?
>>
>>Murphy, Sean M. wrote:
>>
>> 
>>
>>    
>>
>>>>Hi! I can't make QSettings to save an entry.
>>>>/etc/MyFolder - empty folder.
>>>>What's wrong ?
>>>>  
>>>>
>>>>     
>>>>
>>>>        
>>>>
>>>The problem is a basic C++ problem and in my opinion a little Qt problem
>>>too.  The Qt problem is that the QSettings object doesn't actually write
>>>out the values unless the destructor is called.  The C++ problem is that
>>>you are mixing your malloc/free with new/delete.  You called "new" to
>>>create the QSettings object, so you should call "delete" on it, instead
>>>of "free".  The problem with the QSettings object is that you MUST get
>>>it to call its destructor to actually get it to write out the data.
>>>Since you call "free" the destructor never gets called.
>>>
>>>
>>>   
>>>
>>>      
>>>
>>>>#include <qsettings.h>
>>>>
>>>>int main(int argc, char *argv[]) {
>>>>  QSettings *settings = new QSettings(QSettings::Ini);
>>>>  settings->insertSearchPath(QSettings::Unix, "/etc/MyFolder");
>>>>  settings->writeEntry("/test/test", "qwerty123");
>>>>  free(settings);
>>>>  
>>>>
>>>>     
>>>>
>>>>        
>>>>
>>>Change the above line to:
>>>    delete settings;
>>>And it should work fine!
>>>
>>>
>>>
>>>
>>>   
>>>
>>>      
>>>
>>>>  return 0;
>>>>}
>>>>  
>>>>
>>>>     
>>>>
>>>>        
>>>>
>>>Sean
>>>
>>>
>>>
>>>
>>>   
>>>
>>>      
>>>
>> 
>>
>>    
>>
>
>
>  
>

<Prev in Thread] Current Thread [Next in Thread>
  • AW: AW: AW: QSettings, Michael.Soukup <=