PDA

View Full Version : store QSettings in XML for all platforms wanted



nilir
1st July 2010, 12:30
I develope multiplatform portable application. It is targeted to Windows and Linux, but probably can appear for MAC OS. Application has to be portable and must work in any platform. In best case it can be written to SD or flash-memory, and statically linked executables for ALL supported platforms can appear on it. That means user inserts SD card to Linux machine - and starts work. Or he inserts SD to Windows machine and continues work. That's the idea...

I have to save settings to SD card instead of save them to registry on Win-machine. The only one way is save INI file. But why this ancient INI format is the only one I can use? Of course saving settings in XML is much more modern and useful than INI. It is native for MAC. And finaly, instead of INI - XML is multiplatform standard...

Why there is no native ability save settings in XML on ALL supported platforms??? XML support code is well developed for Linux and Windows, and it already exists in Qt MAC's build. Why just not include this code to Qt libraries for all platforms and define QSettings::XmlFormat for QSettings::Format enum?

Please tell me why this hasn't been done yet??? :confused:

SixDegrees
1st July 2010, 12:40
There's no such facility mainly because Windows doesn't support XML preferences. Also because QSettings is designed to be a cross-platform preferences-storage mechanism, so the implementations that are actually in use on supported platforms for storing such information were used. Preferences are stored in a blocked, non-hierarchical format on all platforms; using XML for such a simple format is overkill.

If you want to store XML, just store your XML document in a QString, and assign it as the value of a single key in the QSettings object. Or, just store it in a text file and write your own parser for it.

nilir
1st July 2010, 13:37
But INI is not native for MAC OS... and what?...

As I can see many Qt-programmers prefer XML format for settings. Even there are some third party solutions using QDOMElement. They aren't so useful. But if there is no needed tool - then people try make one. Most useful will be native support in Qt. Just implement QSettings::XmlFormat for all platforms. Viola! Lot's of people will tell THANK YOU!!

SixDegrees
1st July 2010, 13:51
QSettings is meant to produce standards-compliant preference files on the platforms it supports.

If you want to save and restore your very own XML files, there are ample tools availble that let you do that on yourself; if you use the various Qt XML tools, they're cross-platform, to boot. Why you need to use XML to parse a simple key/value, non-hierarchical text file escapes me, but there's nothing stopping you.

nilir
2nd July 2010, 09:50
My settings file is rather hierarchical, not just simple key-value pairs. Now there are 3 levels of hierarchy and it can increrase.

I'm pretty sure programmers have to have choice which one format use. I create multiplatform application using multiplatform toolkit Qt. This application must work on any platform, including MAC OS. But INI files on this platform ar not standard.

Of course I'll use thrid party XML extension for while. Yes, I'll not use INI-format which TT/Nokia created for this. Like many other people around. And I'll not remove my request to implement XML multiplatform support under cover of Qt.