PDA

View Full Version : efficient way to store menu items in file



h123
23rd July 2009, 08:34
my Qt application requires to store the menu information (submenus, menuitems, shortcut keys, etc), to persist across sessions.
Can you please suggest efficient way to store this in file?
And how efficient QSetting is, in storing hierarchical data (without repeating the same info) ?
Thank you.

Lykurg
23rd July 2009, 08:37
And how efficient QSetting is, in storing hierarchical data (without repeating the same info) ?
Good. See QSettings::beginGroup() with QSettings::beginWriteArray().

h123
23rd July 2009, 09:57
Just for illustration, how efficiently the QTreeWidgetItems can be stored using QSetting, without repeating the info like...
<example 'setting.txt' file>
Line1: main_menu/File
Line2: main_menu/File/Print
...
Line 10: main_menu/Edit
Line 11: main_menu/Edit/Copy
...

Here I want to avoid reduandant information that it stores about 'main_menu' and 'File' or 'Edit'.

Thank you.

Lykurg
23rd July 2009, 10:28
Right, I was false, I thought it would be making
[Menu]
[File]
print = xyz
...
Then I think you have to use a custom file format (xml)

or

you can try create a hash with all your informations and use QDataStream & operator<< ( QDataStream & out, const QHash<Key, T> & hash ) (<- and vice versa, but I never have tested that...)

faldzip
23rd July 2009, 12:51
for more compilcated tree structure you can use XML files with DOM API (to have random access to tree structure) or with XmlStreamReader and Writer wich can be better in your case to use reader to read the settings at the beggining and store them with writer at the end (application closing).
Another way is to use SQLite to manage your settings database saved in file (like in the newest QtCreator). You can have than file e.g. settings.db and access it like a database - with SQL statements - and store settings there like in database.

h123
24th July 2009, 07:52
Thank you all for informaion..

faldżip, thank you for suggesting xml option.
I am just wondering how sqlite will be useful, as it stores data in relational manner not in hierarchical level ?

Also, if you have any idea about the hierachical data type in C/C++ (I seem it mentioned in http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2101.html#tr.hierarchy.plain) lib then please let me know.

Any idea, which is better in efficiency, JSON or xml ?

Thank you.