Solved how do something on a window before the user open that window?
-
@mrjj no , i don't have to keep it in existence
i don't mind destroying and re-creating it -
@davidlabib
Ok so im not sure what its not working for you
If you call doAll(false) in constructor
then when Dialog is shown they should all be disabled.
Is that not the case? -
@davidlabib
Then you could follow @mrjj's advice to just do your work in the constructor and not worry about show events.But you really need to explain precisely when you want those widgets to change between enabled & disabled, because I for one don't know what you intend.
-
the default is disabled
but when the user input admin password correct it will enabled the widgets
my problem is to make the widgets disabled by default
if i put doAll(false) in the constructor when soneone fill admin password correct it will enable
but if the user closed editUser and open it again it will be enabled without admin password filling -
@davidlabib
but when the user input admin password correct it will enabled the widgets
When? Do you re-verify the password as he types each character into the line edit?
my problem is to make the widgets disabled by default
Put the disablement into the constructor.
if i put doAll(false) in the constructor when soneone fill admin password correct it will enable
It will not enable unless you tell it to.
but if the user closed editUser and open it again it will be enabled without admin password filling
That is the bit where @mrjj was suggesting you destroy the dialog after using it, and re-create a new one each time it's wanted. Then there is no "open again" from wherever it got to, you always start afresh in the constructor.
-
- Yes , verify the password
- I don't know how to destroy the dialog after the user close the window
-
@davidlabib
1.Yes , verify the password
That does not answer my question. When do you verify the password? As the user types a character at a time (really?)? After he has finished typing (how do you know that?)?
2.I don't know how to destroy the dialog after the user close the window
How do you create the dialog in the first place? With
new
? -
-
the form will enable after the user type all the character correctly without clicking buttons
after he type the last char correct it will enable the window -
by qt designer form class
-
-
@davidlabib said in how do something on a window before the user open that window?:
after he type the last char
how do you know that? What if user enters correct password but then he/she enters one more character?
"by qt designer form class" - this is not the answer to the question. The question is: how do you create the dialog INSTANCE.
Like this:MyDialog *dialog = new MyDialog(this);
?
-
@davidlabib
Further to @jsulm.If you do indeed check the password charaacter by character as it's typed, you will need to have a signal/slot for that and call
doAll(True)
whenever it becomes correct anddoAll(False)
if it then becomes incorrect. That's how you will do the enablement/disablement dynamically at runtime. I think you asked about that. Note that there's still nothing here about "when the dialog is shown", this is something which must be re-done on each character typed.You will create the dialog in one of two ways:
- If you use
new
(creates on the heap), you will usedelete
(or.deleteLater()
) to delete it. - If you have it as a local variable (not a pointer) in a function it will be on the stack, and it will get destroyed when that function goes out of scope.
In either of these two cases you will be re-creating/destroying the dialog each time it is used, and so the constructor can be used to reset the initial state without worrying about when the dialog is "shown".
- If you use
-
@JonB about the last 10 sentences i solved the problem thanks to you.
But about the first part
Yes it's signal and slot but
The widgets is enabled
And the user will not have to fill any thing in admin password field to do the slot
So it must disabled from the beginning -
@davidlabib said in how do something on a window before the user open that window?:
So it must disabled from the beginning
Yes, that's why we already said you should call
doAll(False)
in the contructor so that it starts out disabled, plus calldoAll(True)
/doAll(False)
again as appropriate as each character is typed. -
@JonB i wasn't know how to do that
I seted the disable function in the constructor
and when i was closing the window and open it again doAll wasn't executing
Iam using "new" by the way
So it wasn't destroy the dialog
When i close it
But now i use delete -
@davidlabib
So now you are usingnew
&delete
each time you want to show the dialog you should be finding it is correctly calling the constructor to set disabled at the start of every time it gets shown, right?More worrying is that you say you were using
new
but notdelete
. If you only call thenew
once and then keep the dialog around and reuse it it's not too bad. But if you keep calling anew
and never call a corresponding adelete
or.deleteLater()
your code will "leak memory" by having separate instances of the dialog sitting around in memory unused forever. If you did not know this it's very important you understand how Qt expects you to code when creating widgets withnew
. Just saying.