tags:

views:

236

answers:

3

My Qt application should be able to create/open/save a single "Project" at once. What is the painless way to store project's settings in a file? Should it be XML or something less horrible?

Of course data to be stored in a file is a subject to change over time.

What I need is something like QSettings but bounded to a project in my application rather than to the whole application.

+1  A: 

I order to make it user editable, I would stick to plain text with one key = values by line, like in most of the Linux apps.

However this is only for the settings, not for the complete project's data which I suppose requires more complex structures.

So maybe JSON ?

fa.
+1  A: 

Pro XML:

  • You can have a look at it in an editor
  • You can store any kind of string in any language in it (unicode support)
  • It's simple to learn
  • More than one program can read the same XML
  • It's easy to structure your data with XML. When you use key/value lists, for example, you'll run into problems when you need to save tree-like structures.

Contra XML

  • The result is somewhat bloated
  • Most programming languages (especially old ones like C++) have no good support for XML. The old XML APIs were designed in such a way that they could be implemented in any language (smallest common denominator). 'nuff said.
  • You need to understand the concept of "encoding" (or "charset"). While this may look trivial at first glance, there are some hidden issues which can bite you. So always test your code with some umlauts and even kanji (Japanese characters) to make sure you got it right.
Aaron Digulla
Qt has very good XML api http://doc.trolltech.com/4.0/qtxml.html.
Sharique
This API is based on DOM which, in my book, is not a "very good XML API". I prefer thinks like "html.body.p[3].text = '...'" instead of getRootElement().getChildElement("body").getChildElements("p").get(3).setText("...");
Aaron Digulla
+1  A: 

You can use QSettings to store data in a specific .ini file. From the docs:

Sometimes you do want to access settings stored in a specific file or registry path. On all platforms, if you want to read an INI file directly, you can use the QSettings constructor that takes a file name as first argument and pass QSettings::IniFormat as second argument. For example: QSettings settings("/home/petra/misc/myapp.ini", QSettings::IniFormat);