Results 1 to 5 of 5

Thread: saving settings does not work

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default saving settings does not work

    Hi to all!

    I've subclassed QSettings class and in implementation I have following code:
    Qt Code:
    1. void CApplicationSettings::saveSettings()
    2. {
    3. for (qint16 iIndex=0; iIndex<m_SettingsValues.size(); iIndex++)
    4. {
    5. beginGroup(m_SettingsValues.at(iIndex).strHub);
    6. setValue(m_SettingsValues.at(iIndex).strKey,
    7. m_SettingsValues.at(iIndex).varValue);
    8. endGroup();
    9. } // for
    10.  
    11. // for (qint16 iIndex=0; iIndex<m_SettingsValues.size(); iIndex++)
    12. // {
    13. // if(m_SettingsValues.at(iIndex).strHub==databaseSettingKey)
    14. // {
    15. // beginGroup(databaseSettingKey);
    16. // qDebug() << "m_SettingsValues.at(iIndex).strKey: " << m_SettingsValues.at(iIndex).strKey
    17. // << " " << "m_SettingsValues.at(iIndex).varValue: " << m_SettingsValues.at(iIndex).varValue;
    18. // setValue(m_SettingsValues.at(iIndex).strKey, m_SettingsValues.at(iIndex).varValue.toString());
    19. // endGroup();
    20. // } // if
    21. // } // for
    22.  
    23. // for (qint16 iIndex=0; iIndex<m_SettingsValues.size(); iIndex++)
    24. // {
    25. // if(m_SettingsValues.at(iIndex).strHub==languageSettingsKey)
    26. // {
    27. // beginGroup(languageSettingsKey);
    28. // qDebug() << "m_SettingsValues.at(iIndex).strKey: " << m_SettingsValues.at(iIndex).strKey
    29. // << " " << "m_SettingsValues.at(iIndex).varValue: " << m_SettingsValues.at(iIndex).varValue;
    30. // setValue(m_SettingsValues.at(iIndex).strKey, m_SettingsValues.at(iIndex).varValue.toString());
    31. // endGroup();
    32. // } // if
    33. // } // for
    To copy to clipboard, switch view to plain text mode 
    Result of this class, INI file, after this code looks like that:
    Qt Code:
    1. [dbSettings]
    2. dbHost=0
    3. dbName=0
    4. dbPassword=0
    5. dbType=0
    6. dbUserName=0
    7.  
    8. [langSettings]
    9. langID=0
    10. langTranslatorFile=0
    To copy to clipboard, switch view to plain text mode 
    All values are zeroed, but they must not be. Why?!
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: saving settings does not work

    I've also then added sync(), but no effect ...
    Qt 5.3 Opensource & Creator 3.1.2

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: saving settings does not work

    Have you assured contents of m_SettingsValues? Why not use QSettings in a normal way?

    Qt Code:
    1. {
    2. QSettings settings;
    3. ...
    4. settings.setValue(...);
    5. ...
    6. } // settings object goes out of scope, any unsaved changes will eventually be written to permanent storage
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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 ...
    Qt 5.3 Opensource & Creator 3.1.2

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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.
    J-P Nurmi

Similar Threads

  1. QWidget Settings advanced idea
    By MarkoSan in forum Qt Programming
    Replies: 9
    Last Post: 27th March 2008, 09:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.