PDA

View Full Version : QSettings: copy from ini to xml? Copy group?



TorAn
11th January 2012, 15:45
I have rather complicated QSettings-based confuguration file, that grew by time and became quite large. Originally I selected "ini" format, which in the hindsight appears to be a wrong choice. Now I have to move the configuration to the website where there is no Qt.

My questions are:
1. Is there an easy way to copy a "group" (created with "beginGroup/endGroup" calls) to a new group in the same QSetting-based config file?
Something like non-existent QSetting::copyGroup("currentName", "newName"), so everything iside the group is copied?

2. Is there a way to copy one configuration file format into another? I have an .ini-based config and would like to convert it to xml. Doing it programmatically group by group will be a tedious work. Any converters out there?

Suggestions and comments will be appreciated.

Thanks.

wysota
11th January 2012, 15:51
1. Is there an easy way to copy a "group" (created with "beginGroup/endGroup" calls) to a new group in the same QSetting-based config file?
Something like non-existent QSetting::copyGroup("currentName", "newName"), so everything iside the group is copied?
Yes. QSettings::childKeys() returns all the keys in the current group. You can iterate over them and copy the contents elsewhere.


2. Is there a way to copy one configuration file format into another? I have an .ini-based config and would like to convert it to xml. Doing it programmatically group by group will be a tedious work. Any converters out there?
Sure. Implement an XML backend for QSettings (see QSettings::registerFormat) then open the ini-based settings, use QSettings::allKeys() to get all the keys in the settings and insert the key-value pairs into the xml-based settings.