[Qt-interest] Storing Qt properties to file

Bo Thorsen bo at fioniasoftware.dk
Mon Sep 26 12:43:56 CEST 2011


Hi Robert,

If you write to a .ini file, you can use QSettings and don't have to 
worry about any of this. It just works.

But if you prefer XML or some other file type, you have a bit more work 
to do.

First step is to make sure you don't have locale dependent values 
written. Like numbers are written 1.000,00 in Danish but 1,000.00 in 
English. So you should use something like this:

http://www.fioniasoftware.dk/blog/?p=21

For strings, you should just use UTF-8 as the encoding, then you don't 
have to worry about it.

I hope this helps.

Bo Thorsen.

Den 26-09-2011 11:23, Schimkowitsch Robert skrev:
> Hi,
>
> I want to be able to write the properties of my object to file in a
> locale-independent way, and be able to restore the object using that
> stored information later on.
>
> Before I start reinventing the wheel, I'd like to know whether something
> like this already exists (I couldn't find it, but then again Qt has
> grown big).
>
> My plan includes the following steps. If you happen to know existing
> classes or samples that cover those steps, please let me know!
>
> 1) Read and write QVariant: Handling of basic data types (float is a bit
> tricky, unicode strings might be)
> 2) Write a reader and writer that writes all Q_PROPERTIES of an object
> to an XML file, and reads them again, restoring the object properties.
> By using propertyOffset() of QMetaObject, I should be able to filter out
> base class properties that should not be saved and restored.
>
> 3) Define the needed properties in my objects, and call the reader/writer
>
> Kind regards
>
> *Robert Schimkowitsch*
>
> ------------------------------------------------------------------------
>
> This message and any attachments are solely for the use of the intended
> recipients. They may contain privileged and/or confidential information
> or other information protected from disclosure. If you are not an
> intended recipient, you are hereby notified that you received this email
> in error and that any review, dissemination, distribution or copying of
> this email and any attachment is strictly prohibited. If you have
> received this email in error, please contact the sender and delete the
> message and any attachment from your system.
>
> ANDRITZ HYDRO GmbH
> Rechtsform/ Legal form: Gesellschaft mit beschrankter Haftung / Corporation
> Firmensitz/ Registered seat: Wien
> Firmenbuchgericht/ Court of registry: Handelsgericht Wien
> Firmenbuchnummer/ Company registration: FN 61833 g
> DVR: 0605077
> UID-Nr.: ATU14756806
>
> Thank You.
>
> ------------------------------------------------------------------------
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest


Bo Thorsen,
Fionia Software.

-- 

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk



More information about the Qt-interest-old mailing list