Results 1 to 11 of 11

Thread: Qtopia-4.2 Restoring the Saved Values for QComboBoxes

  1. #1
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Qtopia-4.2 Restoring the Saved Values for QComboBoxes

    Hi,

    I want to restore saved values for qcomboboxes upon
    restarting the application.
    Can you please help me in doing this,

    I am able to write settings to a file using QSettings.
    and storing the file as *.ini format.

    But while reading the settings I am not able to read
    it properly, using settings.value(...) function.

    Can anybody had this problem, please help me out in
    restoring the stored values for QComboBoxes upon restarting the application.

    Or do I need to use any other alternative to restore application values upon restarting the application. Help me with some code.

    Thanks & Regards,
    Arun.

  2. #2
    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: Qtopia-4.2 Restoring the Saved Values for QComboBoxes

    Quote Originally Posted by arunvv View Post
    I want to restore saved values for qcomboboxes upon
    restarting the application.
    Would you mind showing the relevant code what you've got so far and we'll help filling in the gaps?
    J-P Nurmi

  3. #3
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qtopia-4.2 Restoring the Saved Values for QComboBoxes

    Here is the Code :

    Qt Code:
    1. void Settings :: readSettings()
    2. {
    3. QSettings settings("configWda.ini",QSettings::IniFormat);
    4. settings.beginGroup("session");
    5. restoreState(settings.value("Layout").toByteArray());
    6. settings.setValue("WSMTxRate",wsmTxRate);
    7. settings.endGroup();
    8. }
    9.  
    10. void Settings :: writeSettings()
    11. {
    12. QSettings settings("configWda.ini",QSettings::IniFormat);
    13. settings.beginGroup("session");
    14. wsmTxRate = WSMTxRate->currentIndex();
    15. settings.setValue("WSMTxRate",wsmTxRate);
    16. printf("WSMTxRate is : %d \n", wsmTxRate);
    17. //settings.setValue("WSMTxRate",WSMTxRate->currentIndex());
    18. settings.remove("Layout");
    19. settings.setValue("Layout",saveState());
    20. settings.endGroup();
    21. }
    22.  
    23. void Settings :: closeEvent(QCloseEvent *event)
    24. {
    25. writeSettings();
    26. event->accept();
    27. }
    To copy to clipboard, switch view to plain text mode 

    calling the readSettings function in constructor.
    Last edited by wysota; 4th May 2007 at 22:41. Reason: missing [code] tags

  4. #4
    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: Qtopia-4.2 Restoring the Saved Values for QComboBoxes

    readSettings() indeed doesn't restore the current index of the combo box. I think you might be looking for something like this:
    Qt Code:
    1. void Settings :: readSettings()
    2. {
    3. [...]
    4. //settings.setValue("WSMTxRate",wsmTxRate); // <-- wrong
    5. WSMTxRate->setCurrentIndex(settings.value("WSMTxRate").toInt()); // <-- try something like this
    6. [...]
    7. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qtopia-4.2 Restoring the Saved Values for QComboBoxes

    Thanks it worked

    Thanks for your imm. reply.

  6. #6
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qtopia-4.2 Restoring the Saved Values for QComboBoxes

    Hi ,

    I have few more doubts ,
    1) After your recommended changes my application is working fine when I close.
    2) If I kill or send some SIGTERM signal it is not restoring the values changed.
    3) How to handle those changes to reflect even if the application is killed or send SIGTERM siganl.

    Thanks & Regards,
    Arun

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qtopia-4.2 Restoring the Saved Values for QComboBoxes

    Call QSettings::sync() after changing the settings (for example after calling setValue()).

  8. #8
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qtopia-4.2 Restoring the Saved Values for QComboBoxes

    QSettings::sync() is not working.
    I am calling writeSettings() inside closeEvent() function.
    Is it to do any thing with this type calling , for not working QSettings::sync()
    If this doesn't help ,is there any alternative to handle Kernal signals(like kill, SIGTERM).

    Thanks & Regards,
    Arun

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qtopia-4.2 Restoring the Saved Values for QComboBoxes

    If you kill an application closeEvent will not fire, hence writeSettings() will not be called. So you have to make sure the object is synced with the data storage after each call to setValue(). Alternatively register a handler for the SIGTERM signal and save the settings there. Of course this won't work for SIGKILL or SIGSEGV - the first can't be intercepted and the second may be signaled when your application is in an unpredictable state due to invalid memory access.

  10. #10
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qtopia-4.2 Restoring the Saved Values for QComboBoxes

    Can you provide me the source code how to handle Signals with alternative method (not able to sync with QSettings)

    Thanks & Regards
    Arun

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qtopia-4.2 Restoring the Saved Values for QComboBoxes

    man signal

Similar Threads

  1. Replies: 3
    Last Post: 6th March 2007, 18:24

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
  •  
Qt is a trademark of The Qt Company.