PDA

View Full Version : how to get the accept signal by clicking Apply button



weixj2003ld
5th January 2012, 00:14
I create a myDialog inhereted from QDialog,and add an Apply button,as you know,when click Apply button,the slot applyslot() is used and the dialog window should not be closed.

I use myDialog as follows:


myDialog *mydialog=new myDialog (this);

if(mydialog->exec())
{
......
}

for not used accepted() in applyslot(),so applyslot() does not do,how to let the slot applyslot() do and the window does not close?

ChrisW67
5th January 2012, 04:29
Do not do anything in the applyslot() that will close the dialog. That is, do not call close(), accept(), reject(), or done() or anything that calls them.

weixj2003ld
6th January 2012, 00:07
Do not do anything in the applyslot() that will close the dialog. That is, do not call close(), accept(), reject(), or done() or anything that calls them.
If I do as you said,the result of
mydialog->exec() will be false,because only accept() or done() is called ,it will be true.

ChrisW67
6th January 2012, 01:44
If you continue with a modal dialog then it has three buttons:

OK: Press this, pending stuff is done, accept() is called, the dialog closed, and true returned.
Cancel: Press this, pending stuff is not done, reject() is called, the dialog closed, and false returned.
Apply: Press this, pending stuff is done, nothing is done that would close the dialog, and exec() does not return.


If you want a non-modal dialog then call show() not exec(). You do not get a boolean return this way so you may need to reconsider how stuff is done.