PDA

View Full Version : Help: How to save Check box state



Garibalde
27th June 2009, 07:09
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.

cydside
27th June 2009, 07:47
Try to store checkbox state in static variable, ex.:



static bool checkBoxState;

faldzip
27th June 2009, 09:58
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.

Garibalde
28th June 2009, 08:36
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.

martinb0820
1st July 2009, 21:24
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