May 17, 2011

evergreen evergreen
Lab Rat
79 posts

QSettings : custom ini file

 

Hello,

I’m on Windows XP.

I’m using Qsettings in order to save properties. Those properties has different types (int, QSTring, bool…). When I use a classical QSettings that is basically stored on windows registered, no problem. But when i try to use an INI file, the types of settings ar lost (that’s any ascii file so only char).
I would like to know if it’s possible to custom this file in order to give the type of each dtata stored in it.

Thanks

6 replies

May 17, 2011

gedd gedd
Lab Rat
36 posts

An ini file is a text file so you can just get string.
You use QString functions

  1. toDouble (  )
  2. toFloat ()
  3. toInt ( )
  4. toLong ( )
  5. toLower ()
  6. toShort ( )


for number

or for boolean

  1. bool mybool = (myString=="true")?true:false;

etc …

 Signature 

Gedd

May 17, 2011

evergreen evergreen
Lab Rat
79 posts

That means I can’t know the type of data I put into it I guess….

May 17, 2011

gedd gedd
Lab Rat
36 posts

I hope you know the type of data you put into
That means also that string is type of string and nothing else.

Try to use group (aka the ‘key’ in QSettings i think)

[MyInt]

[MyFloat]

 Signature 

Gedd

May 17, 2011

evergreen evergreen
Lab Rat
79 posts

That’s an intersting idea. I already use the arborescence but it could be usefull.
Anyway, after 4 hours looking for a solution about the ini file, if anyone gets the same idea I got, it doesn’t seam possible to modify its protocol to put the type into it.

I’ll check on give this informations by the groups or write my own writing function.

May 17, 2011

Peppy Peppy
Lab Rat
412 posts

You should use class named QVariant [doc.trolltech.com]

For example:

  1. QVariant("DEAD").convert(QVariant::Int);

May 18, 2011

Volker Volker
Ant Farmer
5428 posts

ini files work without problems for me. You’ll have to use QSettings setValue and value methods.

 
  ‹‹ Strange questions about QTableWidget      Gesture conflicts with unity ››

You must log in to post a reply. Not a member yet? Register here!