saving settings does not work
Hi to all!
I've subclassed QSettings class and in implementation I have following code:
Code:
void CApplicationSettings::saveSettings()
{
for (qint16 iIndex=0; iIndex<m_SettingsValues.size(); iIndex++)
{
beginGroup(m_SettingsValues.at(iIndex).strHub);
setValue(m_SettingsValues.at(iIndex).strKey,
m_SettingsValues.at(iIndex).varValue);
endGroup();
} // for
// for (qint16 iIndex=0; iIndex<m_SettingsValues.size(); iIndex++)
// {
// if(m_SettingsValues.at(iIndex).strHub==databaseSettingKey)
// {
// beginGroup(databaseSettingKey);
// qDebug() << "m_SettingsValues.at(iIndex).strKey: " << m_SettingsValues.at(iIndex).strKey
// << " " << "m_SettingsValues.at(iIndex).varValue: " << m_SettingsValues.at(iIndex).varValue;
// setValue(m_SettingsValues.at(iIndex).strKey, m_SettingsValues.at(iIndex).varValue.toString());
// endGroup();
// } // if
// } // for
// for (qint16 iIndex=0; iIndex<m_SettingsValues.size(); iIndex++)
// {
// if(m_SettingsValues.at(iIndex).strHub==languageSettingsKey)
// {
// beginGroup(languageSettingsKey);
// qDebug() << "m_SettingsValues.at(iIndex).strKey: " << m_SettingsValues.at(iIndex).strKey
// << " " << "m_SettingsValues.at(iIndex).varValue: " << m_SettingsValues.at(iIndex).varValue;
// setValue(m_SettingsValues.at(iIndex).strKey, m_SettingsValues.at(iIndex).varValue.toString());
// endGroup();
// } // if
// } // for
Result of this class, INI file, after this code looks like that:
Code:
[dbSettings]
dbHost=0
dbName=0
dbPassword=0
dbType=0
dbUserName=0
[langSettings]
langID=0
langTranslatorFile=0
All values are zeroed, but they must not be. Why?!
Re: saving settings does not work
I've also then added sync(), but no effect ...
Re: saving settings does not work
Have you assured contents of m_SettingsValues? Why not use QSettings in a normal way?
Code:
{
...
settings.setValue(...);
...
} // settings object goes out of scope, any unsaved changes will eventually be written to permanent storage
Re: saving settings does not work
m_SettingsValues is a QList and is filled with data and has size 14 - the number of settings in my application. The reason I've subclassed QSettings is that I need some extended functionality ...
Re: saving settings does not work
So which QSettings functionality are you extending? QSettings doesn't even have much virtual functions besides those it inherits from QObject... That kind of "extending" doesn't seem to give any benefits but just troubles. :) Perhaps you should switch from IS-A to HAS-A relationship.