PDA

View Full Version : how do I discard user changes on widgets



donglebob
28th December 2008, 00:35
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?

Lykurg
28th December 2008, 09:30
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

donglebob
28th December 2008, 13:25
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.

aamer4yu
29th December 2008, 07:33
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 ?

donglebob
29th December 2008, 13:48
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.

donglebob
30th December 2008, 07:50
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...