efficient way to store menu items in file
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.
Re: efficient way to store menu items in file
Quote:
Originally Posted by
h123
And how efficient QSetting is, in storing hierarchical data (without repeating the same info) ?
Good. See QSettings::beginGroup() with QSettings::beginWriteArray().
Re: efficient way to store menu items in file
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.
Re: efficient way to store menu items in file
Right, I was false, I thought it would be making
Code:
[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...)
Re: efficient way to store menu items in file
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.
Re: efficient way to store menu items in file
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/wg...ierarchy.plain) lib then please let me know.
Any idea, which is better in efficiency, JSON or xml ?
Thank you.