how do I discard user changes on widgets
Hi,
I have a QDialog-instance in my MainProgram, which is made for user settings.
It has TableWidgets and ComboBox'es with default values.
The user can make some changes on these widgets values and click SAVE to leave, but
when the user clicks cancel...the whole values of the widgets must be set back to the state before.
The actual problem is that after clicking "cancel" all changes to the widgets are saved.
How can I do that restoring of the widgets content?
Re: how do I discard user changes on widgets
Quote:
Originally Posted by
donglebob
The actual problem is that after clicking "cancel" all changes to the widgets are saved.
That's the point. Simply don't save changes after cancel is pressed. Use exec and have a look at QDialog::DialogCode.
Lykurg
Re: how do I discard user changes on widgets
Hi,
I don't save anything.
My QDialog-Class X is a member of my MainProgram. I create it dynamically in its Ctor.
When the user wants to enter X he clicks on a button and X->exec() will be called.
The dialog X appears, the user changes something (content) on the widgets Y (TableWidget) and Z (ComboBox). Thats all. After closing the X dialog it returns back to the callers slot.
I know that I can see what the result of X-exec() is
Accept: 1
Reject: 0
But the main question is...who saves the dialog content?
Not me... I don't have an explicit saving method or sth like that.
Maybe I should destroy every time the instance of X ??
But that would be ugly...there must be another way of doing this.
Re: how do I discard user changes on widgets
You will need to save the settings somewhere,, either in member variable in program, or in file. How do u provide values to the dialog ?
Re: how do I discard user changes on widgets
The values for the dialog are set by the parent window.
The widgets of the config-dialog-class are public.
If you mean with settings "QSettings", I tried it but I think its just for the position and size of the window, not the content. It failed for me...don't know what I have done wrong.
Re: how do I discard user changes on widgets
Now I solved it with the following steps:
- I added my dialog-class the equal-operator
- I used the dialog codes
First I made a backup of the object, before executing exec().
If the user "rejects" the backuped copy will be recovered...
Thanks again guys...