PDA

View Full Version : saving settings does not work



MarkoSan
12th June 2008, 23:59
Hi to all!

I've subclassed QSettings class and in implementation I have following 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==databaseSet tingKey)
// {
// 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==languageSet tingsKey)
// {
// 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
// } // forResult of this class, INI file, after this code looks like that:
[dbSettings]
dbHost=0
dbName=0
dbPassword=0
dbType=0
dbUserName=0

[langSettings]
langID=0
langTranslatorFile=0All values are zeroed, but they must not be. Why?!

MarkoSan
13th June 2008, 12:21
I've also then added sync(), but no effect ...

jpn
13th June 2008, 19:09
Have you assured contents of m_SettingsValues? Why not use QSettings in a normal way?



{
QSettings settings;
...
settings.setValue(...);
...
} // settings object goes out of scope, any unsaved changes will eventually be written to permanent storage

MarkoSan
13th June 2008, 19:17
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 ...

jpn
13th June 2008, 19:29
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.