Results 1 to 5 of 5

Thread: Help: How to save Check box state

  1. #1
    Join Date
    Jun 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Help: How to save Check box state

    Hi

    I have a form create that uses two check boxes. I have select default "Checked" for both boxes (since the default use of these are true in the software). I open the window at runtime
    and uncheck a box.. every goes as planned. I close the window and reopen it... the check box is AGAIN checked which is not the correct state of the software.

    How to i make a window/form remember the states of the check boxes before i close so that on reopening it, it will be in the last configured state.

    Thanks
    Garibalde.

  2. #2
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Help: How to save Check box state

    Try to store checkbox state in static variable, ex.:

    Qt Code:
    1. static bool checkBoxState;
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help: How to save Check box state

    And your checkboxes are used to control some settings or what? Because when i have a window with checkbox for example in some IDE to control if the files sould be autosaved before compiling then I need to store the choosen option in variable which I can check before compiling. So when window with that setting is being opened I check the setting somewhere where it is set and needed and set the proper state to the checkboxes.
    I mean that the checkboxes are used usually to define some settings stored somewhere where they are needed (or with a QSettings), so when you reopen the window with checkboxes their state is set properly to saved settings. So it is hard to say how you should save the checkbox state if we don't know what do you need that checkbox for.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  4. #4
    Join Date
    Jun 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help: How to save Check box state

    Thanks Problem solved. I thought there might be a built in method to save the last state of the window. However i implemented it by as suggest by reading the current states of the feature selections and setting the checkbox upon opening the windows/page.

    Thanks.

  5. #5
    Join Date
    Aug 2008
    Location
    Cherry Hill, NJ USA
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help: How to save Check box state

    Are you creating a single instance of the form on the heap using new and then using show() and hide(), or instantiating the form on the stack? That could be the problem.

    The QSpinBoxes should maintain their state whether the form they are on is hidden or being shown, and you should be able to use the QCheckBoxes as their own state variables when the s/w wants to make a decision based on whether or not they are checked.

    As faldzip notes, if you want to have the states remembered the next time the application runs, use QSettings.

    Martin

Similar Threads

  1. Replies: 0
    Last Post: 2nd May 2008, 07:57
  2. Check and Uncheck on a Dir Tree?
    By vishal.chauhan in forum Qt Programming
    Replies: 2
    Last Post: 3rd July 2007, 11:55
  3. How to check a file for changes since last save
    By nmather in forum General Programming
    Replies: 2
    Last Post: 21st April 2007, 23:43
  4. save animate to gif
    By Dmitry in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2006, 16:35
  5. What does "Save All" actually save?
    By Mariane in forum Newbie
    Replies: 7
    Last Post: 31st January 2006, 13:23

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.